/* ==========================================================================
   HEditor UI Styles
   ========================================================================== */
:root {
    --he-bg-color: #ffffff;
    --he-border-color: #ddd;
    --he-toolbar-bg: #fff;
    --he-btn-hover: #f5f5f5;
    --he-btn-active: #f2f2f2;
    --he-icon-color: #555;
    --he-primary-color: #535a8c;
}

/* 1. 컨테이너 및 툴바 */
.he-container {
    border: 1px solid var(--he-border-color);
    background: var(--he-bg-color);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
    box-sizing: border-box;
    position: relative;
}

.he-toolbar {
    background: var(--he-toolbar-bg);
    border-bottom: 1px solid var(--he-border-color);
    padding: 5px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    transition: height 0.3s ease;
    box-sizing: border-box;
    position: relative;
}
.he-toolbar.expanded {
    height: auto;
    overflow: visible;
}

/* 2. 버튼 및 그룹 */
.he-group {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-right: 8px;
    padding-right: 8px;
    border-right: 1px solid #eee;
}
.he-group:last-child {
    border-right: none;
}

.he-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--he-icon-color);
    transition: background 0.2s;
    font-size: 13px;
    padding: 0;
}
.he-btn:hover {
    background: var(--he-btn-hover);
}
.he-btn.active {
    background: var(--he-btn-active);
    color: #000;
}
.he-btn img, .he-btn svg {
    width: 16px;
    height: 16px;
    display: block;
    pointer-events: none;
}
.he-btn.disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
    background: transparent !important;
}

/* 툴바 토글러 (모바일/확장용) */
.he-toolbar-toggler {
    position: absolute;
    right: 5px;
    top: 8px;
    width: 30px;
    height: 30px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    color: #555;
}
.he-toolbar.expanded .he-toolbar-toggler svg {
    transform: rotate(180deg);
}

/* 3. 셀렉트 박스 (폰트 크기 등) */
.he-select {
    height: 28px;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0 5px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    background: #fff;
    color: #333;
}

/* 4. 편집 영역 & 소스 보기 */
.he-content {
    overflow-y: auto;
    outline: none;
    padding: 20px;
}

.he-source-view {
    display: none;
    width: 100%;
    padding: 20px !important;
    border: none !important;
    outline: none !important;
    resize: none !important;
    box-sizing: border-box !important;
    line-height: 1.6;
    font-family: 'Consolas', monospace !important;
    font-size: 13px;
    white-space: pre !important;
    background: #1e1e1e !important;
    color: #d4d4d4 !important;
    border-radius: 0px !important;
}

/* 5. 링크 입력 레이어 (통합됨) */
.he-link-layer {
    position: absolute;
    display: none;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 10px;
    z-index: 10002;
    width: 260px;
    box-sizing: border-box;
    font-size: 13px;
    flex-direction: column;
    gap: 8px;
}
.he-link-layer.open {
    display: flex;
}

.he-link-input-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* 링크 입력창 스타일 (강제 리셋 포함) */
.he-link-layer .he-link-input {
    box-sizing: border-box !important;
    display: block !important;
    flex: 1;
    width: 100% !important;
    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;
    margin: 0 !important;
    padding: 0 8px !important;
    border: 1px solid #ddd !important;
    border-radius: 3px !important;
    outline: none !important;
    box-shadow: none !important;
    background: #ffffff !important;
    color: #333333 !important;
    font-family: inherit !important;
    font-size: 13px !important;
    line-height: normal !important;
    letter-spacing: normal !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.he-link-layer .he-link-input:focus {
    border-color: #535a8c !important;
    box-shadow: 0 0 0 2px rgba(83, 90, 140, 0.1) !important;
    background: #ffffff !important;
}

.he-link-layer .he-link-input::placeholder {
    color: #999 !important;
    opacity: 1 !important;
}

.he-link-option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #555;
}

/* 체크박스 스타일 (강제 리셋) */
.he-link-layer input[type="checkbox"].he-link-target {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    appearance: auto !important;
    -webkit-appearance: checkbox !important;
    width: 13px !important;
    height: 13px !important;
    position: static !important;
    margin: 0 4px 0 0 !important;
    padding: 0 !important;
    border: 1px solid #ccc !important;
    background: #fff !important;
    vertical-align: middle !important;
    cursor: pointer;
    z-index: auto !important;
}

.he-link-layer .he-link-option-row label {
    display: flex !important;
    align-items: center !important;
    cursor: pointer;
    line-height: 1;
}

.he-link-btns {
    display: flex;
    gap: 5px;
}
.he-link-btn {
    padding: 4px 8px;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
    border-radius: 3px;
    font-size: 11px;
}
.he-link-btn.primary {
    background: #535a8c;
    color: #fff;
    border-color: #535a8c;
}
.he-link-btn:hover {
    opacity: 0.9;
}

/* 6. 플로팅 툴바 */
.he-floating-toolbar {
    position: absolute;
    display: none;
    background: #333;
    border-radius: 5px;
    padding: 5px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10000;
    gap: 5px;
    align-items: center;
}
.he-floating-toolbar::after {
    content: '';
    position: absolute;
    top: -10px;
    left: 15px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent #333 transparent;
}
.he-floating-toolbar .he-btn {
    color: #fff;
    width: 32px;
    height: 32px;
}
.he-floating-toolbar .he-btn:hover {
    background: #555;
}
.he-floating-toolbar .he-btn.active {
    background: #007bff;
}
.he-floating-toolbar .he-btn img {
    filter: invert(1);
}
.he-floating-separator {
    width: 1px;
    height: 20px;
    background: #555;
    margin: 0 5px;
    display: inline-block;
}

/* 7. 리사이즈 바 */
.he-bottom-bar {
    height: 12px;
    background-color: #f8f9fa;
    border-top: 1px solid #ddd;
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
}
.he-resize-grip {
    width: 40px;
    height: 4px;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
}

/* 8. 드롭다운 (Align 등) */
.he-align-dropdown {
    position: absolute;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    padding: 5px;
    z-index: 10001;
    display: none;
    flex-direction: row;
    gap: 4px;
}
.he-align-dropdown.open {
    display: flex;
}
.he-align-item {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.he-align-item:hover {
    background-color: #f0f0f0;
}

/* 더보기 버튼 (우측 끝 정렬) */
.he-more-toggle {
    margin-left: auto; /* 핵심: 툴바의 나머지 공간을 차지하여 우측으로 밀어냄 */
    border-left: 1px solid transparent; 
}
.he-more-toggle.active {
    background-color: var(--he-btn-active);
}

/* 더보기 드롭다운 레이어 */
.he-more-layer {
    position: absolute;
    display: none;
    top: 40px; right: 5px; /* JS에서 계산하지만 초기값 설정 */
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10005;
    
    padding: 8px;
    width: max-content;
    max-width: 200px;
    
    /* 그리드 배치 (한 줄에 4개씩 등) 또는 플렉스 */
    display: none; /* open 클래스로 제어 */
    flex-wrap: wrap;
    gap: 4px;
}
.he-more-layer.open {
    display: flex;
}

/* 드롭다운 내 아이템 스타일 */
.he-more-layer .he-more-item {
    width: 32px; height: 32px;
}

.he-more-separator {
    width: 1px; height: 24px; background: #eee; margin: 4px 0;
}

.he-fontsize-layer {
    position: absolute;
    display: none;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 12px;
    z-index: 10005;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}
.he-fontsize-layer.open {
    display: flex;
}

/* 슬라이더 스타일 */
.he-fontsize-slider {
    flex: 1;
    cursor: pointer;
    width: 120px;
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

/* 슬라이더 핸들 (Chrome/Safari) */
.he-fontsize-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #535a8c;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}
.he-fontsize-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* 현재 픽셀 값 표시 텍스트 */
.he-fontsize-value {
    font-size: 13px;
    font-weight: bold;
    color: #333;
    min-width: 35px;
    text-align: right;
}

/* 9. 다크 모드 */
.he-container.he-dark {
    --he-bg-color: #1e1e1e;
    --he-border-color: #333333;
    --he-toolbar-bg: #252526;
    --he-btn-hover: #37373d;
    --he-btn-active: #094771;
    --he-icon-color: #c5c5c5;
}
.he-container.he-dark .he-content {
    color: #d4d4d4;
}
.he-container.he-dark .he-group {
    border-right-color: #3e3e42;
}
.he-container.he-dark .he-btn.active {
    color: #ffffff;
}
.he-container.he-dark .he-btn img {
    filter: invert(0.9);
}
.he-container.he-dark .he-select {
    background: #333;
    color: #ccc;
    border-color: #3e3e42;
}
.he-container.he-dark .he-bottom-bar {
    background-color: #2d2d2d;
    border-top-color: #333;
}

.he-container.he-dark .he-more-layer {
    background: #252526; border-color: #333;
}
.he-container.he-dark .he-more-separator {
    background: #3e3e42;
}

.he-container.he-dark .he-fontsize-layer {
    background: #252526;
    border-color: #333;
}
.he-container.he-dark .he-fontsize-slider {
    background: #444;
}
.he-container.he-dark .he-fontsize-value {
    color: #eee;
}