/**
 * 폼 필드 공통 스타일
 * 세 파일에서 공통으로 사용되는 폼 필드 스타일
 */

/* 폼 필드 래퍼 */
.form-field-wrapper {
    position: absolute;
    /* 기본값: 절대 위치 (그룹 외부 필드용) */
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
    transition: all 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

/* 디자이너 모드에서는 테두리/그림자 제거 (CanvasItem이 처리) */
.form-field-wrapper.is-designer {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    transform: none !important;
}

/* 그룹 내부 필드는 그리드 레이아웃 사용 */
.group-fields-container .form-field-wrapper {
    position: static;
    /* 그리드 레이아웃에서는 static 사용 */
}

.form-field-wrapper:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px color-mix(in srgb, var(--color-primary) 20%, transparent);
    /* 움직임 제거 */
    /* transform: translateY(-2px); */
}

.form-field-wrapper label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin: 0;
    padding: 6px 8px 4px 8px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: move;
    line-height: 1.1;
    flex-shrink: 0;
    /* 세로 압축 시 폰트 및 패딩 미세 조정 */
    font-size: calc(0.8rem * var(--v-ratio, 1));
    padding: calc(6px * var(--v-ratio, 1)) 8px calc(4px * var(--v-ratio, 1)) 8px;
}

.form-field-wrapper input,
.form-field-wrapper textarea,
.form-field-wrapper select {
    width: 100%;
    padding: 6px 8px;
    border: none;
    border-radius: 0;
    font-size: 0.8rem;
    flex-grow: 1;
    background: #fff;
    line-height: 1.2;
    min-height: 24px;
    margin: 0;
}

.form-field-wrapper input:focus,
.form-field-wrapper textarea:focus,
.form-field-wrapper select:focus {
    outline: none;
    background: #fafbfc;
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

.form-field-wrapper textarea {
    resize: none;
    min-height: 30px;
}

/* 작은 필드에 대한 조정 */
.form-field-wrapper[style*="height: 48px"],
.form-field-wrapper[style*="height: 60px"] {
    padding: 0;
}

.form-field-wrapper[style*="height: 48px"] label,
.form-field-wrapper[style*="height: 60px"] label {
    font-size: 0.75rem;
    padding: 4px 6px 2px 6px;
}

.form-field-wrapper[style*="height: 48px"] input,
.form-field-wrapper[style*="height: 48px"] select,
.form-field-wrapper[style*="height: 60px"] input,
.form-field-wrapper[style*="height: 60px"] select {
    font-size: 0.75rem;
    padding: 4px 6px;
    min-height: 20px;
}

/* Radio 및 Checkbox 그룹 스타일 */
.checkbox-group,
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: calc(0.5rem * var(--v-ratio, 1)) 1rem;
    /* row-gap column-gap */
    padding: calc(4px * var(--v-ratio, 1)) 6px;
    /* Align with other inputs */
    flex: 1;
    /* Occupy remaining space instead of fixed height */
    height: auto;
    min-height: 0;
    align-content: flex-start;
    overflow-y: auto;
    /* Add scroll for overflow */
    box-sizing: border-box;
}

.checkbox-option,
.radio-option {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    /* Match other inputs */
    line-height: 1.2;
}

.checkbox-option label,
.radio-option label {
    cursor: pointer;
    white-space: nowrap;
}

.checkbox-option input,
.radio-option input {
    cursor: pointer;
    margin: 0;
    width: auto;
    /* Override default width */
    flex-shrink: 0;
}

/* 검색 가능한 셀렉트 스타일 */
.form-field-wrapper.is-searchable-select {
    overflow: visible;
    /* Allow dropdown to show */
}

.form-field-wrapper.is-searchable-select.open,
.form-field-wrapper:has(.searchable-select-wrapper.open),
.form-field-wrapper:has(.notion-style-select-wrapper.dropdown-open),
.form-field-wrapper:has(.notion-style-checkbox-wrapper.dropdown-open),
.form-field-wrapper:has(.notion-style-radio-wrapper.dropdown-open) {
    z-index: 9999 !important;
    overflow: visible !important;
    /* 드롭다운이 열려있을 때 모든 요소보다 위에 표시 */
}

/* 드롭다운이 열려있을 때 wrapper의 hover 효과 비활성화 (transform으로 인한 stacking context 변경 방지) */
.form-field-wrapper.is-searchable-select.open:hover {
    transform: none !important;
    border-color: var(--border-color) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07) !important;
}

/* 드롭다운이 열려있을 때 필드 라벨이 드롭다운보다 위에 오지 않도록 */
.form-field-wrapper.is-searchable-select.open label {
    z-index: 1;
    position: relative;
    cursor: default !important;
    /* 드래그 커서 비활성화 */
    pointer-events: none;
    /* 호버 및 클릭 효과 비활성화 */
    user-select: none;
    /* 텍스트 선택 비활성화 */
}

.searchable-select-wrapper {
    position: relative;
    flex: 1;
    /* Occupy remaining space */
    height: auto;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.searchable-select-input {
    width: 100%;
    padding: 0 6px;
    border: none;
    background: transparent;
    font-size: 0.7rem;
    /* Match other inputs */
    line-height: 1.2;
    height: 100%;
    box-sizing: border-box;
}

.searchable-select-input:focus {
    outline: none;
}

.searchable-select-options {
    display: none;
    position: absolute;
    top: calc(100% + 15px);
    /* Unified spacing */
    left: -1px;
    right: -1px;
    background: white;
    border: 1px solid var(--primary-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 150px;
    overflow-y: auto;
    z-index: 10000;
    /* 드롭다운 옵션 리스트가 최상위에 표시 */
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    /* 마우스 이벤트를 확실히 가로채도록 */
}

.searchable-select-wrapper.open .searchable-select-options {
    display: block;
}

.searchable-select-option {
    padding: 6px 8px;
    cursor: pointer;
    font-size: 0.7rem;
    /* Match input */
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.searchable-select-option:hover {
    background: var(--primary-light);
}

.searchable-select-option.selected {
    background: var(--primary-light);
    font-weight: 600;
}

.searchable-select-option.hidden {
    display: none;
}

/* 카테고리 헤더 스타일 */
.searchable-select-category-header {
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted, #666);
    background: var(--hover-background, #f8f9fa);
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    cursor: default;
    pointer-events: none;
    user-select: none;
}

.searchable-select-category-header.hidden {
    display: none;
}

/* 레벨별 들여쓰기 */
.searchable-select-category-level-0 {
    padding-left: 12px;
}

.searchable-select-category-level-1 {
    padding-left: 24px;
}

.searchable-select-category-level-2 {
    padding-left: 36px;
}

/* 노션 스타일 드롭다운용 카테고리 헤더 */
.notion-dropdown-category-header {
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted, #666);
    background: var(--hover-background, #f8f9fa);
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    cursor: default;
    pointer-events: none;
    user-select: none;
}

.notion-dropdown-category-header.hidden {
    display: none;
}

/* 노션 드롭다운 레벨별 들여쓰기 */
.notion-dropdown-category-level-0 {
    padding-left: 12px;
}

.notion-dropdown-category-level-1 {
    padding-left: 24px;
}

.notion-dropdown-category-level-2 {
    padding-left: 36px;
}

/* 옵션 모달용 카테고리 헤더 */
.option-modal-category-header {
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted, #666);
    background: var(--hover-background, #f8f9fa);
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    cursor: default;
    pointer-events: none;
    user-select: none;
}

.option-modal-category-header.hidden {
    display: none;
}

/* 옵션 모달 레벨별 들여쓰기 */
.option-modal-category-level-0 {
    padding-left: 12px;
}

.option-modal-category-level-1 {
    padding-left: 24px;
}

.option-modal-category-level-2 {
    padding-left: 36px;
}

/* 노션 스타일 체크박스/라디오/드롭다운 */
.notion-style-checkbox-wrapper,
.notion-style-radio-wrapper,
.notion-style-select-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    /* Occupy remaining space correctly */
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.notion-input-area {
    position: relative;
    min-height: calc(32px * var(--v-ratio, 1));
    flex: 1;
    /* Occupy all available space in its wrapper */
    height: auto;
    padding: calc(4px * var(--v-ratio, 1)) 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    align-content: flex-start;
    cursor: text;
    box-sizing: border-box;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

/* 드롭다운이 열려있을 때는 overflow를 visible로 변경하여 드롭다운이 보이도록 */
/* Removed to prevent scroll disappearing: overflow handled by structure */
/*.notion-style-checkbox-wrapper.dropdown-open .notion-input-area,
.notion-style-radio-wrapper.dropdown-open .notion-input-area,
.notion-style-select-wrapper.dropdown-open .notion-input-area {
    overflow: visible;
}*/

.notion-style-checkbox-wrapper.dropdown-open .notion-search-input,
.notion-style-radio-wrapper.dropdown-open .notion-search-input,
.notion-style-select-wrapper.dropdown-open .notion-search-input {
    overflow: visible;
}

.notion-input-area:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 10%, transparent);
}

.notion-search-input {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    align-items: center;
    align-content: flex-start;
    padding: 0;
    background: transparent;
    cursor: text;
    position: relative;
    overflow-x: hidden;
    overflow-y: visible !important;
    /* Fixed: Force remove double scrollbar */
    height: auto;
    /* Internal contents drive height, wrapper handles scroll */
    max-height: none !important;
}

.notion-search-input-wrapper {
    display: inline-flex;
    align-items: center;
    position: relative;
    flex: 0 0 auto;
}

.notion-search-icon {
    position: absolute;
    left: 4px;
    font-size: 0.7rem;
    color: #999;
    pointer-events: none;
    z-index: 1;
    display: inline-block;
}

.notion-search-input-field {
    flex: 0 0 auto;
    min-width: 40px !important;
    width: 40px;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    padding: 4px 4px 4px 20px;
    font-size: 0.7rem;
    background: transparent;
    line-height: 1.2;
    white-space: nowrap;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    box-sizing: border-box;
}

.notion-search-input-field:focus {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
}

.notion-selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.notion-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 4px;
    font-size: 0.7rem;
    line-height: 1.4;
    flex-shrink: 0;
    white-space: nowrap;
}

.notion-tag-text {
    white-space: nowrap;
}

.notion-tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--primary-dark);
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.2s;
    font-size: 0.6rem;
}

.notion-tag-remove:hover {
    background: rgba(0, 0, 0, 0.1);
}

.notion-tag-remove i {
    pointer-events: none;
}

/* '선택된 항목 없음' 상태인 경우(두 클래스 모두 지원) 부모의 고정 높이를 해제하고 내부 내용물까지 축소 */
.form-field-wrapper:has(.no-tags-msg, .no-selected-items-msg) {
    height: auto !important;
    min-height: 0 !important;
    /* 이제 내용물이 줄어들 것이므로 0으로 설정 가능 */
}

/* 빈 상태일 때 라벨 여백 및 폰트 축소 */
.form-field-wrapper:has(.no-tags-msg, .no-selected-items-msg) label {
    padding-top: calc(0.1rem * var(--v-ratio, 1)) !important;
    padding-bottom: calc(0.1rem * var(--v-ratio, 1)) !important;
}

.no-tags-msg,
.no-selected-items-msg {
    color: var(--text-muted);
    font-size: calc(0.65rem * var(--v-ratio, 1));
    font-style: italic;
    display: block;
    line-height: 1;
}

.form-field-wrapper:has(.no-tags-msg, .no-selected-items-msg) .notion-input-area {
    min-height: 0 !important;
    padding: 2px 6px !important;
}

.notion-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 15px);
    /* Unified spacing */
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10000;
    /* 노션 스타일 드롭다운도 최상위에 표시 */
    padding: 4px;
    margin-top: 2px;
    pointer-events: auto;
    /* 마우스 이벤트를 확실히 가로채도록 */
}

/* 드롭다운이 .notion-search-input 안에 있을 때 위치 조정 */
/* Legacy style removed: .notion-search-input .notion-dropdown */

.notion-style-checkbox-wrapper.dropdown-open .notion-dropdown,
.notion-style-radio-wrapper.dropdown-open .notion-dropdown,
.notion-style-select-wrapper.dropdown-open .notion-dropdown {
    display: block;
}

/* 드롭다운이 열려있을 때 wrapper도 높은 z-index 적용 */
.notion-style-checkbox-wrapper.dropdown-open,
.notion-style-radio-wrapper.dropdown-open,
.notion-style-select-wrapper.dropdown-open {
    z-index: 9999;
    position: relative;
}

/* 노션 스타일 드롭다운이 열려있을 때 wrapper의 hover 효과 비활성화 (transform으로 인한 stacking context 변경 방지) */
.form-field-wrapper:has(.notion-style-select-wrapper.dropdown-open):hover,
.form-field-wrapper:has(.notion-style-checkbox-wrapper.dropdown-open):hover,
.form-field-wrapper:has(.notion-style-radio-wrapper.dropdown-open):hover {
    transform: none !important;
    border-color: var(--border-color) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07) !important;
}

/* 노션 스타일 드롭다운이 열려있을 때 필드 라벨이 드롭다운보다 위에 오지 않도록 */
.form-field-wrapper:has(.notion-style-select-wrapper.dropdown-open) label,
.form-field-wrapper:has(.notion-style-checkbox-wrapper.dropdown-open) label,
.form-field-wrapper:has(.notion-style-radio-wrapper.dropdown-open) label {
    z-index: 1;
    position: relative;
    cursor: default !important;
    /* 드래그 커서 비활성화 */
    pointer-events: none;
    /* 호버 및 클릭 효과 비활성화 */
    user-select: none;
    /* 텍스트 선택 비활성화 */
}

.notion-dropdown-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    justify-content: flex-start;
}

.notion-dropdown-option:hover {
    background: var(--primary-light);
}

.notion-dropdown-option input[type="checkbox"],
.notion-dropdown-option input[type="radio"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
    flex-grow: 0;
}

.notion-dropdown-option label {
    flex: 1;
    cursor: pointer;
    font-size: 0.7rem;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    font-weight: normal;
    color: var(--text-color);
}

.notion-dropdown-option.hidden {
    display: none;
}

/* 읽기 전용 스타일 */
.notion-style-checkbox-wrapper[data-readonly="true"] .notion-input-area,
.notion-style-radio-wrapper[data-readonly="true"] .notion-input-area,
.notion-style-select-wrapper[data-readonly="true"] .notion-input-area {
    cursor: default;
    background: #f5f5f5;
}

.notion-style-checkbox-wrapper[data-readonly="true"] .notion-search-input {
    display: none;
}

.notion-style-checkbox-wrapper[data-readonly="true"] .notion-tag-remove,
.notion-style-radio-wrapper[data-readonly="true"] .notion-tag-remove,
.notion-style-select-wrapper[data-readonly="true"] .notion-tag-remove {
    display: none;
}

/* 드롭다운이 열려있을 때 다른 필드들의 호버 효과 비활성화 */
body:has(.form-field-wrapper.is-searchable-select.open) .form-field-wrapper:not(.is-searchable-select.open):hover,
body:has(.notion-style-select-wrapper.dropdown-open) .form-field-wrapper:not(:has(.notion-style-select-wrapper.dropdown-open)):hover,
body:has(.notion-style-checkbox-wrapper.dropdown-open) .form-field-wrapper:not(:has(.notion-style-checkbox-wrapper.dropdown-open)):hover,
body:has(.notion-style-radio-wrapper.dropdown-open) .form-field-wrapper:not(:has(.notion-style-radio-wrapper.dropdown-open)):hover {
    border-color: var(--border-color) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07) !important;
    transform: none !important;
}

/* 위키 검색 아이콘 스타일 */
.wiki-search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    color: #6c757d;
    font-size: 0.85em;
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s;
    vertical-align: middle;
    flex-shrink: 0;
}

.wiki-search-icon:hover {
    opacity: 1;
    color: #007bff;
    text-decoration: none;
}

.wiki-search-icon i {
    font-size: 0.9em;
}

/* 노션 스타일 드롭다운 옵션 내 위키 아이콘 */
.notion-dropdown-option .wiki-search-icon {
    margin-left: auto;
    flex-shrink: 0;
}

/* 기존 스타일 옵션 내 위키 아이콘 */
.checkbox-option .wiki-search-icon,
.radio-option .wiki-search-icon {
    margin-left: auto;
    flex-shrink: 0;
}

/* 검색 가능한 셀렉트 옵션 내 위키 아이콘 */
.searchable-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.searchable-select-option-text {
    flex: 1;
    min-width: 0;
}

.searchable-select-option .wiki-search-icon {
    margin-left: 8px;
    flex-shrink: 0;
}

/* 모달 옵션 내 위키 아이콘 */
.option-modal-item {
    display: flex;
    align-items: center;
    position: relative;
}

.option-modal-item-text {
    flex: 1;
}

.option-modal-item .wiki-search-icon {
    margin-left: auto;
    flex-shrink: 0;
}

/* Smart Autocomplete Field Styles */
.smart-text-field {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.smart-textarea {
    flex: 1;
    min-height: 80px;
    resize: none;
    border: none;
    /* Internal border handled by wrapper */
    padding: 8px;
    font-size: 0.9rem;
    line-height: 1.5;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    /* Ensure font matches */
}

.smart-textarea:focus {
    outline: none;
}

.smart-suggestions {
    border-top: 1px solid var(--border-color, #e0e0e0);
    background: #f8f9fa;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 60px;
    overflow-y: auto;
    flex-shrink: 0;
}

.suggestion-chip {
    display: inline-flex;
    align-items: center;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    color: #333;
    gap: 4px;
}

.suggestion-chip:hover {
    background: #e9ecef;
    border-color: #ced4da;
    transform: translateY(-1px);
}

.suggestion-chip.is-favorite {
    border-color: #ffd700;
    background: #fffbf0;
}

.suggestion-chip.is-detected {
    border-color: #28a745;
    background: #e8f5e9;
    color: #1e7e34;
    font-weight: bold;
}

.suggestion-chip.is-suggestion {
    border-color: #17a2b8;
    background: #e0f7fa;
    color: #006064;
    box-shadow: 0 0 3px rgba(23, 162, 184, 0.4);
}

.suggestion-chip.add-new {
    border-style: dashed;
    border-color: var(--primary-color, #007bff);
    color: var(--primary-color, #007bff);
    background: rgba(0, 123, 255, 0.05);
}

.suggestion-chip.add-new:hover {
    background: rgba(0, 123, 255, 0.1);
}

.chip-text {
    font-weight: 500;
}

.chip-actions {
    display: inline-flex;
    gap: 2px;
    margin-left: 4px;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.suggestion-chip:hover .chip-actions {
    opacity: 1;
}

.suggestion-chip .btn-fav,
.suggestion-chip .btn-del {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 0.8rem;
    /* Smaller icon */
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
}

.suggestion-chip .btn-fav:hover {
    color: #ffd700;
    background: rgba(0, 0, 0, 0.05);
}

.suggestion-chip .btn-fav.active {
    color: #ffd700;
}

.suggestion-chip .btn-del:hover {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
}