/**
 * KAICE Post Tag Field Styles (Theme Version)
 * 포스트 검색 및 멀티 칩 태그 필드 스타일
 * 
 * 태그 칩 스타일은 tag-styles.css의 .tag-item 클래스를 사용합니다.
 */

/* ==================== 
   Post Tag Wrapper 
   ==================== */
.kaice-post-tag-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

/* ==================== 
   Post Tag Container 
   ==================== */
.kaice-post-tag-container {
    padding: 6px 8px;
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

/* kaice-post-tag-selected가 비어있을 때 gap 제거 */
.kaice-post-tag-container:has(.kaice-post-tag-selected:empty) {
    gap: 0;
}

.kaice-post-tag-container:focus-within {
    border-color: var(--theme-main-color);
    box-shadow: 0 0 0 1px var(--theme-main-color);
}

/* ==================== 
   Selected Posts Area 
   ==================== */
.kaice-post-tag-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 0 0 auto;
}

/* ==================== 
   Post Tag (Chip) - tag-styles.css 사용
   ==================== */
/* 
   태그 칩 스타일은 tag-styles.css의 .tag-item 클래스를 사용합니다.
   field-post-tag.js에서 자동으로 'tag-item' 클래스로 생성됩니다.
   
   생성되는 HTML 구조:
   <span class="tag-item" data-post-id="123">
       <span class="tag-item-text">포스트 제목</span>
       <span class="tag-item-remove">×</span>
   </span>
   
   태그 스타일 커스터마이징은 tag-styles.css를 수정하세요.
*/

/* ==================== 
   Search Input Wrapper 
   ==================== */
.kaice-post-tag-search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 150px;
}

/* ==================== 
   Search Input 
   ==================== */
.form-group input[type="text"].kaice-post-tag-search-input {
    width: 100%;
    padding: 0;
    margin: 0;
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    background: transparent;
    border: none;
    outline: none;
    line-height: 1.4;
    min-height: auto;
}

.kaice-post-tag-search-input::placeholder {
    color: var(--theme-hint-text-color);
}

.kaice-post-tag-search-input:focus {
    outline: none;
}

/* ==================== 
   Suggestions Dropdown 
   ==================== */
.kaice-post-tag-suggestions {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    z-index: 9999;
    background: white;
    border: 1px solid var(--theme-card-border);
    border-radius: var(--theme-card-radius);
    box-shadow: 0 3px 30px rgba(25, 30, 35, 0.1);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    animation: kaiceFadeIn 0.2s ease;
    scrollbar-width: thin;
    scrollbar-color: #aaa #f1f1f1;
}

/* kaice-field-picker-container는 JavaScript에서 생성하는 검색 결과 컨테이너입니다 */
.kaice-field-picker-container.post-tag {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    z-index: 9999;
    background: white;
    border: 1px solid var(--theme-card-border);
    border-radius: var(--theme-card-radius);
    box-shadow: 0 3px 30px rgba(25, 30, 35, 0.1);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    animation: kaiceFadeIn 0.2s ease;
    scrollbar-width: thin;
    scrollbar-color: #aaa #f1f1f1;
}

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

/* 웹킷 브라우저용 스크롤바 */
.kaice-post-tag-suggestions::-webkit-scrollbar {
    width: 8px;
}

.kaice-post-tag-suggestions::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.kaice-post-tag-suggestions::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.kaice-post-tag-suggestions::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ==================== 
   Suggestion Item 
   ==================== */
.kaice-post-tag-suggestion {
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--theme-card-border);
}

.kaice-post-tag-suggestion:last-child {
    border-bottom: none;
}

.kaice-post-tag-suggestion:hover {
    background: var(--theme-info-bg);
}

.kaice-post-tag-suggestion.active {
    background: var(--theme-info-bg);
}

.kaice-post-tag-suggestion-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kaice-post-tag-title {
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    font-weight: 600;
}

.kaice-post-tag-subtitle {
    font-size: var(--theme-font-size-small);
    color: var(--theme-main-color);
}

.kaice-post-tag-meta {
    font-size: var(--theme-font-size-small);
    color: var(--theme-hint-text-color);
    display: block;
}

/* kaice-field-picker-item (JavaScript에서 생성되는 항목) */
.kaice-field-picker-item.post-tag {
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--theme-card-border);
}

.kaice-field-picker-item.post-tag:last-child {
    border-bottom: none;
}

.kaice-field-picker-item.post-tag:hover {
    background: var(--theme-info-bg);
}

.kaice-field-picker-item.post-tag.active {
    background: var(--theme-info-bg);
}

.kaice-field-picker-item.post-tag .kaice-post-tag-suggestion-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kaice-field-picker-item.post-tag .kaice-post-tag-title {
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
    color: var(--theme-text-color);
    font-weight: 600;
}

.kaice-field-picker-item.post-tag .kaice-post-tag-subtitle {
    font-size: var(--theme-font-size-small);
    color: var(--theme-main-color);
}

.kaice-field-picker-item.post-tag .kaice-post-tag-meta {
    font-size: var(--theme-font-size-small);
    color: var(--theme-hint-text-color);
    display: block;
}

/* ==================== 
   Message States 
   ==================== */
.kaice-post-tag-message {
    padding: 16px 12px;
    text-align: center;
    color: var(--theme-hint-text-color);
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
}

.kaice-post-tag-message.error {
    color: var(--theme-error-color);
}

/* ==================== 
   Empty State 
   ==================== */
.kaice-post-tag-container:empty::before {
    content: attr(data-placeholder);
    color: var(--theme-hint-text-color);
    font-size: var(--theme-font-size-body);
    font-family: var(--theme-font-normal);
}

/* ==================== 
   Responsive 
   ==================== */
@media (max-width: 768px) {
    .kaice-post-tag-search-input {
        font-size: var(--theme-font-size-small);
    }
    
    .kaice-post-tag-suggestions {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90%;
        max-width: 400px;
        max-height: 70vh;
        z-index: 9999;
        animation: modalAlertSlideIn 0.3s ease-out;
    }
    
    .kaice-post-tag-suggestion {
        padding: 14px 12px;
    }

}

@media (max-width: 480px) {
    .kaice-post-tag-search-input-wrapper {
        min-width: 120px;
    }
}

/* ==================== 
   Loading State 
   ==================== */
.kaice-post-tag-suggestions.loading .kaice-post-tag-message::after {
    content: '...';
    animation: kaiceLoadingDots 1.4s infinite;
}

@keyframes kaiceLoadingDots {
    0%, 20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60%, 100% {
        content: '...';
    }
}

/* ==================== 
   Accessibility 
   ==================== */
.kaice-post-tag-container:focus-within {
    outline: none;
}

.kaice-post-tag-search-input:focus-visible {
    outline: none;
}

.kaice-post-tag-suggestion:focus-visible {
    outline: 2px solid var(--theme-main-color);
    outline-offset: 2px;
}

/* ==================== 
   Animations 
   ==================== */
@keyframes modalAlertSlideIn {
    from {
        transform: translate(-50%, -50%) translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%) translateY(0);
        opacity: 1;
    }
}

/* ==================== 
   Disabled State 
   ==================== */
.kaice-post-tag-container.disabled {
    opacity: 0.6;
    pointer-events: none;
    background-color: var(--theme-item-bg);
}

.kaice-post-tag-container.disabled .kaice-post-tag-search-input {
    cursor: not-allowed;
}

/* ==================== 
   Integration with Form Groups 
   ==================== */
.form-group .kaice-post-tag-wrapper {
    margin-top: 6px;
}

.form-group label + .kaice-post-tag-wrapper {
    margin-top: 0;
}

/* ==================== 
   Info Box (선택된 포스트 정보)
   ==================== */
.kaice-post-tag-info-box {
    margin-top: 12px;
    padding: 16px;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: var(--theme-input-radius);
}

.kaice-post-info-item {
    padding: 12px;
    background-color: white;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.kaice-post-info-item + .kaice-post-info-item {
    margin-top: 12px;
}

.kaice-post-info-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.kaice-post-info-subtitle {
    font-size: 14px;
    color: #666;
    margin-bottom: 8px;
}

.kaice-post-info-meta-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kaice-post-info-meta {
    font-size: 13px;
    color: #555;
    line-height: 1.5;
}

.kaice-post-info-meta strong {
    color: #333;
    font-weight: 600;
}
