/**
 * NSKit Widget Styles v1.0
 *
 * Self-Managed Widget의 기본 스타일
 * Prefix: nsk-* (NSKit 전용, 충돌 방지)
 */

/* ============================================
   Textarea Widget
   ============================================ */

.ns-textarea {
    display: block;
    width: 100%;
}

.ns-textarea .textarea-wrapper {
    position: relative;
    width: 100%;
}

.ns-textarea .textarea-field {
    width: 100%;
    min-height: 60px;  /* 3줄 정도 */
    padding: 12px 16px;
    border: 1px solid var(--nskit-border-color);
    border-radius: var(--nskit-widget-radius);
    font-size: var(--nskit-font-size-base);
    line-height: 1.5;
    color: var(--nskit-text-primary);
    background: white;
    resize: none;  /* auto-resize로 처리 */
    overflow-y: hidden;
    transition: all 0.2s;
    box-sizing: border-box;
}

.ns-textarea .textarea-field::placeholder {
    color: var(--nskit-text-disabled);
}

.ns-textarea .textarea-field:focus {
    outline: none;
    border-color: var(--nskit-primary);
    box-shadow: var(--nskit-widget-focus-ring);
}

.ns-textarea.disabled .textarea-field {
    background: var(--nskit-bg-secondary);
    color: var(--nskit-text-disabled);
    cursor: not-allowed;
}

/* Character Count */
.ns-textarea .char-count {
    position: absolute;
    right: 12px;
    bottom: 8px;
    font-size: 12px;
    color: var(--nskit-text-secondary);
    pointer-events: none;
}

.ns-textarea.focused .char-count {
    color: var(--nskit-primary);
}

/* ============================================
   Checkbox Widget
   ============================================ */

.ns-checkbox {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* 단일 Checkbox (items 없는 경우) */
.ns-checkbox > .nsk-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 2px solid #D4D4D8;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ns-checkbox > .nsk-icon::before {
    content: '✓';
    font-size: 12px;
    color: #fff;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
}

/* Hover (unchecked) */
.ns-checkbox:not(.checked) > .nsk-icon:hover {
    border-color: var(--nskit-primary);
    background-color: rgba(79, 70, 229, 0.05);
}

/* Checked State (최우선) */
.ns-checkbox.checked > .nsk-icon {
    background-color: var(--nskit-primary);
    border-color: var(--nskit-primary);
}

.ns-checkbox.checked > .nsk-icon::before {
    opacity: 1;
    transform: scale(1);
}

/* Hover (checked) - checked 상태 유지하면서 약간 어둡게 */
.ns-checkbox.checked > .nsk-icon:hover {
    background-color: var(--nskit-primary-hover);
    border-color: var(--nskit-primary-hover);
}

.ns-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s;
    user-select: none;
}

.ns-checkbox-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Checkbox Icon (24x24 박스, 실제 20x20) */
.ns-checkbox-item .nsk-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--nskit-icon-size);     /* 24px */
    height: var(--nskit-icon-size);
    padding: var(--nskit-icon-padding); /* 2px */
    border: 1px solid var(--nskit-border-color);
    border-radius: var(--nskit-widget-radius-sm);
    background-color: white;
    transition: all var(--nskit-transition-base);
    flex-shrink: 0;
    font-size: var(--nskit-icon-actual); /* 20px */
}

/* SVG 아이콘 스타일 */
.ns-checkbox-item .nsk-icon svg,
.ns-checkbox-item .nsk-item-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.ns-checkbox-item .nsk-icon::before {
    content: '✓';
    font-size: 12px;
    color: #fff;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
}

/* Checked State (Float UI Primary) */
.ns-checkbox-item.checked .nsk-icon {
    background-color: var(--nskit-primary);
    border-color: var(--nskit-primary);
}

.ns-checkbox-item.checked .nsk-icon::before {
    opacity: 1;
    transform: scale(1);
}

/* Label (nsk- prefix로 충돌 방지) */
.ns-checkbox-item .nsk-label {
    font-size: 14px;
    color: #333;
    line-height: 1.5;
}

/* Disabled State */
.ns-checkbox-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ============================================
   Radio Mode (is-single="true")
   ============================================ */

/* Radio 모드에서는 동그란 아이콘 */
.ns-checkbox-item.radio-mode .nsk-icon {
    border-radius: 50%;  /* 동그랗게! */
}

/* Radio 체크 시 작은 원 */
.ns-checkbox-item.radio-mode.checked .nsk-icon::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: #fff;
    border-radius: 50%;
    opacity: 1;
    transform: scale(1);
}

/* ============================================
   Input Widget
   ============================================ */

.ns-input {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
}

/* Label (Namespace 보호) */
.ns-input .label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 4px;
}

/* Required Indicator */
.ns-input .label.required::after {
    content: ' *';
    color: #dc3545;
}

/* ===== Input Wrapper (Icon/Button이 있을 때) ===== */
.ns-input .input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Input Field (Float UI 스타일) ===== */
.ns-input .input-field {
    padding: 10px 14px;
    border: 1px solid var(--nskit-border-color);
    border-radius: var(--nskit-widget-radius);
    font-size: var(--nskit-font-size-sm);
    font-family: var(--nskit-font-family);
    outline: none;
    transition: all var(--nskit-transition-base);
    background-color: white;
    color: var(--nskit-text-primary);
    flex: 1;
    box-sizing: border-box;
}

/* Icon이 있을 때 padding 조정 */
.ns-input .input-wrapper:has(.nsk-icon.left) .input-field {
    padding-left: 36px;  /* Icon 공간 확보 */
}

.ns-input .input-wrapper:has(.nsk-icon.right:not(.nsk-button)) .input-field {
    padding-right: 36px;  /* Icon 공간 확보 */
}

.ns-input .input-field::placeholder {
    color: #999;
}

/* Focus State (Float UI ring) */
.ns-input.focused .input-field,
.ns-input .input-field:focus {
    border-color: var(--nskit-primary);
    box-shadow: var(--nskit-widget-focus-ring);
}

/* Disabled State */
.ns-input.disabled .input-field,
.ns-input .input-field:disabled {
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

/* ===== Icon Variant (24x24 박스, 실제 20x20) ===== */
.ns-input .nsk-icon {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--nskit-icon-size);      /* 24px */
    height: var(--nskit-icon-size);
    padding: var(--nskit-icon-padding); /* 2px */
    font-size: var(--nskit-icon-actual); /* 실제 20px */
    color: var(--nskit-text-secondary);
    z-index: 1;
}

/* SVG 아이콘 스타일 */
.ns-input .nsk-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.ns-input .nsk-icon.left {
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.ns-input .nsk-icon.right {
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.ns-input .nsk-icon.clickable {
    cursor: pointer;
    transition: color 0.2s;
}

.ns-input .nsk-icon.clickable:hover {
    color: #007bff;
}

/* ===== Icon Classes (스타일만, content는 JS에서) ===== */
/* Icon content는 ICON_MAP에서 렌더링됨 */
/* 여기서는 개별 아이콘 스타일 정의 가능 */

.nsk-icon.search { color: #6c757d; }
.nsk-icon.eye { color: #6c757d; }
.nsk-icon.clear { color: #dc3545; }
.nsk-icon.user { color: #007bff; }
.nsk-icon.email { color: #007bff; }
.nsk-icon.phone { color: #28a745; }
.nsk-icon.lock { color: #6c757d; }

/* ===== Button Variant (Outside - 기본) ===== */
.ns-input .nsk-button {
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    background-color: #007bff;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.ns-input .nsk-button:hover {
    background-color: #0056b3;
}

.ns-input .nsk-button:active {
    transform: scale(0.98);
}

/* Button Inside (is-inside="true") */
.ns-input .nsk-button.inside {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 12px;
    font-size: 13px;
}

/* Button Inside일 때 Input padding 조정 */
.ns-input .input-wrapper:has(.nsk-button.inside) .input-field {
    padding-right: 80px;  /* 버튼 공간 확보 */
}

/* Button Disabled (Timer 동작 중) */
.ns-input .nsk-button.disabled,
.ns-input .nsk-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Button with Timer (MM:SS 표시) */
.ns-input .nsk-button.timer-running {
    font-family: monospace;
    background-color: #6c757d;
}

/* ============================================
   Select Widget
   ============================================ */

.ns-select {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    min-width: 200px;
}

/* Label */
.ns-select .label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 4px;
}

.ns-select .label.required::after {
    content: ' *';
    color: #dc3545;
}

/* Select Wrapper */
.ns-select .select-wrapper {
    position: relative;
}

/* Trigger (Float UI 스타일) */
.ns-select .select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid var(--nskit-border-color);
    border-radius: var(--nskit-widget-radius);
    background-color: white;
    cursor: pointer;
    user-select: none;
    transition: all var(--nskit-transition-base);
    min-height: 40px;
}

.ns-select .select-trigger:hover {
    border-color: var(--nskit-border-hover);
    background-color: var(--nskit-bg-hover);
}

.ns-select.open .select-trigger {
    border-color: var(--nskit-primary);
    box-shadow: var(--nskit-widget-focus-ring);
}

/* Trigger Text */
.ns-select .select-value {
    flex: 1;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Placeholder */
.ns-select .select-trigger:not(.has-value) .select-value {
    color: #999;
}

/* Chevron Icon */
.ns-select .select-trigger .nsk-icon.chevron {
    margin-left: 8px;
    font-size: 12px;
    color: #666;
    transition: transform 0.2s;
}

.ns-select.open .select-trigger .nsk-icon.chevron {
    transform: rotate(180deg);
}

/* Dropdown (Float UI 스타일) */
.ns-select .select-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 320px;
    background-color: white;
    border: 1px solid var(--nskit-border-color);
    border-radius: var(--nskit-widget-radius);
    box-shadow: var(--nskit-shadow-lg);
    z-index: 1000;
    display: none;
    overflow: hidden;
    animation: slideDown 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ns-select.open .select-dropdown {
    display: block;
}

/* Detached Dropdown (render-target이 self가 아닌 경우) */
.select-dropdown.detached {
    position: absolute;  /* JS에서 위치 계산 */
    top: 0;
    left: 0;
    right: auto;
    max-height: 300px;
    background-color: #fff;
    border: 2px solid #007bff;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;  /* 더 높은 z-index */
    display: none;
    overflow: hidden;
    animation: slideDown 0.2s ease-out;
}

/* Detached Dropdown이 열릴 때 (JS에서 직접 제어) */
.select-dropdown.detached.show {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Search Input */
.ns-select .select-search {
    position: relative;
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.ns-select .select-search .search-input {
    width: 100%;
    padding: 8px 32px 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
}

.ns-select .select-search .search-input:focus {
    border-color: #007bff;
}

.ns-select .select-search .nsk-icon.search {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: #999;
    pointer-events: none;
}

/* Items Container */
.ns-select .select-items {
    max-height: 240px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar */
.ns-select .select-items::-webkit-scrollbar {
    width: 6px;
}

.ns-select .select-items::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.ns-select .select-items::-webkit-scrollbar-track {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Select Item */
.ns-select .select-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.15s;
    user-select: none;
    border-bottom: 1px solid #f5f5f5;
}

.ns-select .select-item:last-child {
    border-bottom: none;
}

.ns-select .select-item:hover {
    background-color: rgba(0, 123, 255, 0.05);
}

.ns-select .select-item.selected {
    background-color: rgba(0, 123, 255, 0.1);
    font-weight: 500;
}

/* Multi Select - Checkbox */
.ns-select .select-item .nsk-icon.checkbox {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 2px solid #ddd;
    border-radius: 3px;
    background-color: #fff;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ns-select .select-item .nsk-icon.checkbox::before {
    content: '✓';
    font-size: 12px;
    color: #fff;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
}

.ns-select .select-item.selected .nsk-icon.checkbox {
    background-color: #007bff;
    border-color: #007bff;
}

.ns-select .select-item.selected .nsk-icon.checkbox::before {
    opacity: 1;
    transform: scale(1);
}

/* Item Icon */
.ns-select .select-item .nsk-item-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* Item Text */
.ns-select .select-item .select-item-text {
    flex: 1;
    font-size: 14px;
    color: #333;
}

/* Single Select - Check Icon */
.ns-select .select-item .nsk-icon.check {
    font-size: 14px;
    color: #007bff;
    opacity: 0;
    transition: opacity 0.2s;
}

.ns-select .select-item.selected .nsk-icon.check {
    opacity: 1;
}

/* Empty State */
.ns-select .select-empty {
    padding: 20px;
    text-align: center;
    font-size: 14px;
    color: #999;
}

/* Disabled State */
.ns-select.disabled .select-trigger {
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
    pointer-events: none;
}

.ns-select.disabled .select-trigger .select-value {
    color: #999;
}
