/* 테이블 페이지 전용 스타일 - UserOutput 테마 기반 */

.table-main {
    min-height: calc(100vh - var(--common-header-offset, 0px));
    background: var(--bg-app);
    padding: 0 16px;
}

.table-container {
    display: flex;
    align-items: flex-start;
    gap: 0;
}

/* 사이드바 - sticky로 스크롤 시 고정 */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-paper);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--common-header-offset, 108px);
    max-height: calc(100vh - var(--common-header-offset, 108px));
    overflow: hidden;
    z-index: 100;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    border: 1px solid var(--border-color);
    border-right: none;
    align-self: stretch;
}

.tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.table-layout {
    flex: 1;
    min-height: calc(100vh - var(--common-header-offset, 0px));
    background: var(--background);
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* 메인 콘텐츠 */
.main-content {
    display: flex;
    flex-direction: column;
    background: var(--background);
    min-width: 0;
}

.sidebar-header {
    height: 56px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-paper);
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-header .ut-btn-small {
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    font-size: 12px;
    height: 30px;
}

.sidebar-header .ut-btn-small:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* 트리 구조 */
.tree-item {
    margin-bottom: 1px;
}

.tree-node {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    color: var(--text-primary);
}

.tree-node:hover {
    background: var(--primary-light);
}

.tree-node.active {
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 600;
}

.tree-toggle {
    width: 16px;
    height: 16px;
    margin-right: 6px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast);
    font-size: 12px;
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.tree-icon svg {
    width: 16px;
    height: 16px;
}

.tree-label {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.tree-actions {
    display: flex;
    gap: 2px;
    margin-left: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
}

.tree-node:hover .tree-actions {
    opacity: 1;
    visibility: visible;
}

.tree-action-btn {
    width: 22px;
    height: 22px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.tree-action-btn:hover {
    background: var(--background);
}

/* 수정 버튼 (첫번째 액션) */
.tree-rename-btn:hover {
    color: var(--primary-color);
}

/* 삭제 버튼 (마지막 액션) */
.tree-action-btn:last-child:hover {
    color: var(--danger-color);
}

/* 인라인 이름 수정 입력 필드 */
.tree-rename-input {
    flex: 1;
    padding: 3px 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--background);
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-sm);
    outline: none;
    box-shadow: 0 0 0 2px var(--focus-ring);
    min-width: 80px;
    max-width: 150px;
}

.tree-rename-input:focus {
    border-color: var(--primary-hover);
}

/* 편집 중인 노드 상태 */
.tree-node.editing {
    background: var(--primary-light);
}

.tree-node.editing .tree-actions {
    opacity: 1;
    visibility: visible;
}

.tree-children {
    margin-left: 20px;
    display: none;
}

.tree-children.expanded {
    display: block;
}

/* 사이드바 항목 추가 버튼 공통 스타일 */
.tree-add-item-btn,
.tree-add-folder-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: calc(100% - 24px);
    margin: 4px 12px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tree-add-item-btn:hover,
.tree-add-folder-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.tree-add-item-btn svg,
.tree-add-folder-btn svg {
    flex-shrink: 0;
    opacity: 0.6;
}

.tree-add-item-btn:hover svg,
.tree-add-folder-btn:hover svg {
    opacity: 1;
}

/* 폴더 내부 파일 추가 버튼/인라인 필드 - 더 들여쓰기 */
.tree-add-item-btn,
.tree-inline-file {
    margin-left: 36px;
    width: calc(100% - 48px);
}

/* 최상위 폴더 추가 버튼 */
.tree-add-folder-btn {
    margin-top: 8px;
    border-style: dashed;
}

/* 인라인 입력 필드 (폴더/파일 추가) */
.tree-inline-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 12px;
    padding: 8px 10px;
    background: var(--background);
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-sm);
    box-shadow: 0 0 0 3px var(--focus-ring);
    overflow: visible;
}

.tree-inline-input-wrapper svg {
    flex-shrink: 0;
    color: var(--primary-color);
}

.tree-inline-input {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    background: var(--background);
    color: var(--text-primary);
}

.tree-inline-input:focus {
    border-color: var(--primary-color);
}

.tree-inline-input::placeholder {
    color: var(--text-tertiary);
}

/* 저장/취소 버튼 - 말풍선 오버레이 */
.tree-inline-actions {
    position: absolute;
    top: -28px;
    right: 0;
    display: flex;
    gap: 4px;
    padding: 5px 8px;
    background: var(--text-primary);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

/* 말풍선 꼬리 */
.tree-inline-actions::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 16px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--text-primary);
}

.tree-inline-save-btn,
.tree-inline-cancel-btn {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.tree-inline-save-btn {
    background: var(--primary-color);
    color: white;
}

.tree-inline-save-btn:hover {
    background: var(--primary-hover);
}

.tree-inline-cancel-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.tree-inline-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 빈 상태 메시지 */
.tree-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-tertiary);
}

.tree-empty svg {
    margin-bottom: 10px;
    opacity: 0.3;
}

.tree-empty p {
    font-size: 13px;
    line-height: 1.5;
}

/* 온보딩 빈 상태 (폴더 없을 때) */
.tree-onboarding {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.tree-onboarding-icon {
    position: relative;
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tree-onboarding-icon::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-color), #2563eb);
    border-radius: 50%;
    opacity: 0.1;
    animation: onboardingPulse 2s ease-in-out infinite;
}

.tree-onboarding-icon svg {
    position: relative;
    z-index: 1;
    width: 40px;
    height: 40px;
    color: var(--primary-color);
    opacity: 1;
}

@keyframes onboardingPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.2;
    }
}

.tree-onboarding-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.tree-onboarding-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 24px;
    max-width: 200px;
}

/* 시작하기 CTA 버튼 */
.tree-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--primary-color), #ca8a04);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(202, 138, 4, 0.35);
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.tree-cta-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.15));
    opacity: 0;
    transition: opacity 0.25s ease;
}

.tree-cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(202, 138, 4, 0.45);
}

.tree-cta-btn:hover::before {
    opacity: 1;
}

.tree-cta-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(202, 138, 4, 0.3);
}

.tree-cta-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* 보조 힌트 텍스트 */
.tree-onboarding-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    font-size: 11px;
    color: var(--text-tertiary);
}

.tree-onboarding-hint svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

/* 온보딩 상태의 인라인 입력 필드 */
.tree-inline-onboarding {
    margin: 40px 20px;
    animation: onboardingInputSlide 0.3s ease-out;
}

@keyframes onboardingInputSlide {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: auto;
}

.tab-content.active {
    display: flex;
}

/* 툴바 - 사이드바 헤더와 높이 통일 */
.toolbar {
    height: 56px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-paper);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-radius: 0 var(--radius-lg) 0 0;
}

.toolbar-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.toolbar-actions {
    display: none;
    align-items: center;
    gap: 6px;
}

.toolbar-actions[style*="flex"] {
    display: flex;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.tool-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    font-size: 13px;
    padding: 0;
    color: var(--text-primary);
    position: relative;
    user-select: none;
}

.tool-btn:hover {
    background: var(--primary-color);
    color: white;
}

.tool-btn.active {
    background: var(--primary-color);
    color: white;
}

.tool-btn:focus-visible {
    outline: 2px solid var(--focus-ring);
}

/* 툴팁 */
.tool-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: 10;
}

.tool-btn:hover::after {
    opacity: 1;
}

.color-picker {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    transition: all var(--transition-fast);
}

.color-picker:hover {
    border-color: var(--primary-color);
}

.color-picker:focus-visible {
    outline: 2px solid var(--focus-ring);
}

.font-size-display {
    min-width: 24px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    user-select: none;
}

/* 테이블 래퍼 */
.table-wrapper {
    flex: 1;
    overflow: auto;
    padding: 0;
    background: var(--background);
    position: relative;
    z-index: 1;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    text-align: center;
}

.empty-state svg {
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 14px;
}

/* 테이블 스켈레톤 로딩 */
.table-skeleton {
    background: var(--background);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.skeleton-header {
    display: flex;
    background: var(--bg-paper);
    border-bottom: 1px solid var(--border-color);
}

.skeleton-header .skeleton-cell {
    height: 42px;
}

.skeleton-row {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-row:last-child {
    border-bottom: none;
}

.skeleton-cell {
    flex: 1;
    height: 48px;
    background: linear-gradient(90deg,
            var(--bg-paper) 0%,
            #f0f0ed 50%,
            var(--bg-paper) 100%);
    background-size: 200% 100%;
    border-right: 1px solid var(--border-color);
}

.skeleton-cell:last-child {
    border-right: none;
}

.skeleton-animate {
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

@keyframes skeletonShimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* 테이블 섹션 (다중 테이블) */
.table-section {
    margin-bottom: 32px;
}

.table-section:last-child {
    margin-bottom: 0;
}

/* 편집 가능한 테이블 */
.editable-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--background);
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.editable-table th {
    background: var(--bg-paper);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

/* 정답 헤더 - 삭제 버튼 포함 */
.th-answer {
    position: relative;
}

.table-delete-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--danger-color);
    background: var(--error-bg);
    border: 1px solid var(--danger-color);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
}

.editable-table thead tr:hover .table-delete-btn {
    opacity: 1;
    visibility: visible;
}

.table-delete-btn:hover {
    background: var(--danger-color);
    color: white;
}

.table-delete-btn svg {
    flex-shrink: 0;
}

.editable-table td {
    padding: 0;
    border: 1px solid var(--border-color);
    position: relative;
    z-index: 1;
    vertical-align: top;
    height: 1px;
    /* 행 높이 동기화를 위한 트릭 */
}

.cell-content {
    min-height: 38px;
    height: 100%;
    padding: 10px 14px;
    outline: none;
    cursor: text;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    transition: all var(--transition-fast);
    border: 2px solid transparent;
    color: var(--text-primary);
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.cell-content:hover {
    background: var(--primary-light);
}

.cell-content:focus {
    background: #fef9e7;
    border-color: var(--primary-color);
}

.cell-content.focused {
    background: #fef9e7;
    border-color: var(--primary-color);
}

.cell-content:empty:before {
    content: attr(data-placeholder);
    color: var(--text-tertiary);
}

/* 정답 셀 - 삭제 버튼 오버레이용 */
.answer-cell {
    position: relative;
}

/* 행 삭제 버튼 - 말풍선 스타일 */
.row-delete-btn {
    position: absolute;
    top: -28px;
    right: 8px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: var(--danger-color);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 10;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
    white-space: nowrap;
}

/* 말풍선 꼬리 */
.row-delete-btn::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 12px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--danger-color);
}

.row-delete-btn:hover {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
}

.row-delete-btn:hover::after {
    border-top-color: #dc2626;
}

/* 행 hover 또는 셀 focus 시 삭제 버튼 표시 */
.editable-table tbody tr:hover .row-delete-btn,
.editable-table tbody tr:focus-within .row-delete-btn {
    opacity: 1;
    visibility: visible;
}

/* 되돌리기 버튼 - 말풍선 스타일 */
.row-undo-btn {
    position: absolute;
    top: -32px;
    right: 8px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: undoBtnPop 0.3s ease-out;
}

@keyframes undoBtnPop {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(4px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* 되돌리기 버튼 말풍선 꼬리 */
.row-undo-btn::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 12px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #2563eb;
}

.row-undo-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.5);
    transform: translateY(-1px);
}

.row-undo-btn:hover::after {
    border-top-color: #1d4ed8;
}

/* 카운트다운 타이머 */
.undo-timer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
}

/* 삭제 대기 상태의 행 */
.editable-table tbody tr.pending-delete {
    background: #fef2f2;
}

.editable-table tbody tr.pending-delete .row-undo-btn {
    opacity: 1;
    visibility: visible;
}

/* 콘텐츠 숨김 상태 (규격 유지) */
.cell-content.content-hidden {
    min-height: 38px;
    background: repeating-linear-gradient(45deg,
            transparent,
            transparent 8px,
            rgba(239, 68, 68, 0.05) 8px,
            rgba(239, 68, 68, 0.05) 16px);
    cursor: default;
}

/* 행 추가 버튼 */
.add-row-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.add-row-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

.add-row-btn span {
    font-size: 16px;
    font-weight: 600;
}

/* 플로팅 툴바 */
.floating-toolbar {
    position: absolute;
    display: none;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--text-primary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.floating-toolbar.visible {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.floating-toolbar-arrow {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--text-primary);
}

.ftool-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 13px;
    transition: background 0.15s ease;
}

.ftool-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ftool-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 4px;
}

.ftool-color-label {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s ease;
}

.ftool-color-label:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ftool-color-icon {
    font-size: 14px;
    font-weight: 700;
    color: #ff0000;
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.5);
}

.ftool-color-input {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.ftool-size {
    min-width: 20px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    user-select: none;
}

/* 문제풀이 모드 */
.solve-header {
    height: 56px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-paper);
    flex-shrink: 0;
}

.solve-header h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.solve-actions {
    display: flex;
    gap: 8px;
}

.score-display {
    padding: 16px;
    background: var(--primary-light);
    border-bottom: 1px solid var(--border-color);
}

.score-card {
    text-align: center;
}

.score-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.score-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 2px;
    color: var(--primary-color);
}

.score-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

/* 문제풀이 테이블 */
.solve-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--background);
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.solve-table th {
    background: var(--bg-paper);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.solve-table td {
    padding: 0;
    border: 1px solid var(--border-color);
    vertical-align: top;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
}

.solve-table td:first-child {
    padding: 10px 14px;
}

.solve-input {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 0;
    font-size: 13px;
    outline: none;
    transition: all var(--transition-fast);
    resize: none;
    overflow: hidden;
    min-height: 40px;
    line-height: 1.5;
    font-family: inherit;
    display: block;
    box-sizing: border-box;
    color: var(--text-primary);
    background: transparent;
}

.solve-input:focus {
    background: #fef9e7;
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

.solve-input.correct {
    background: var(--success-bg);
}

.solve-input.incorrect {
    background: var(--error-bg);
}

/* 정답보기 말풍선 버튼 컨테이너 */
.solve-answer-wrapper {
    position: relative;
}

.show-answer-tooltip {
    position: absolute;
    top: -38px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #1e293b, #334155);
    color: white;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: all 0.2s ease;
    z-index: 100;
    border: none;
    white-space: nowrap;
}

/* 말풍선 꼬리 */
.show-answer-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 16px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #334155;
}

/* 호버 효과 */
.show-answer-tooltip:hover {
    background: linear-gradient(135deg, #334155, #475569);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

/* 포커스 시 표시 */
.solve-answer-wrapper:focus-within .show-answer-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* 아이콘 */
.show-answer-tooltip svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* 활성화 상태 (정답이 표시된 상태) */
.show-answer-tooltip.active {
    background: linear-gradient(135deg, #16a34a, #22c55e);
}

.show-answer-tooltip.active::after {
    border-top-color: #22c55e;
}

/* 정답 표시 팝업 */
.answer-reveal-popup {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #fef9c3, #fef08a);
    border: 1px solid #fbbf24;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #92400e;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.25s ease;
    z-index: 99;
}

.answer-reveal-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.answer-reveal-popup::before {
    content: '💡 정답:';
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #b45309;
    margin-bottom: 4px;
}

/* 실시간 유사도 표시 */
.similarity-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.similarity-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.similarity-bar {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.similarity-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s ease;
}

.similarity-fill.low {
    background: #ef4444;
}

.similarity-fill.medium {
    background: #f59e0b;
}

.similarity-fill.high {
    background: #22c55e;
}

.similarity-percent {
    font-size: 12px;
    font-weight: 700;
    min-width: 40px;
    text-align: right;
    transition: color 0.3s ease;
}

.similarity-percent.low {
    color: #ef4444;
}

.similarity-percent.medium {
    color: #f59e0b;
}

.similarity-percent.high {
    color: #22c55e;
}

.answer-feedback {
    display: none;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
}

.answer-feedback.show {
    display: block;
}

.answer-feedback.correct {
    color: var(--success-color);
    background: var(--success-bg);
}

.answer-feedback.incorrect {
    color: var(--danger-color);
    background: var(--error-bg);
}

/* 모달 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(68, 64, 60, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2147483648;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--background);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.25s ease-out;
    border: 1px solid var(--border-color);
}

.modal-content.modal-sm {
    max-width: 360px;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px) scale(0.98);
        opacity: 0;
    }

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

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-tertiary);
    line-height: 1;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    color: var(--danger-color);
    background: var(--error-bg);
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    transition: all var(--transition-fast);
    color: var(--text-primary);
    background: var(--background);
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* 스크롤바 스타일 (UserOutput과 동일) */
.user-table-page ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.user-table-page ::-webkit-scrollbar-track {
    background: transparent;
}

.user-table-page ::-webkit-scrollbar-thumb {
    background: #d6d3d1;
    border-radius: 10px;
}

.user-table-page ::-webkit-scrollbar-thumb:hover {
    background: #a8a29e;
}

/* 반응형 */
/* ==========================================
   테이블 반응형 디자인
   ========================================== */

/* 태블릿 (최대 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
        min-width: 220px;
    }

    .toolbar-actions {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .editable-table th,
    .editable-table td {
        padding: 0;
    }

    .cell-content {
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* 모바일 태블릿 (최대 768px) */
@media (max-width: 768px) {
    .table-main {
        padding: 0 8px;
        padding-top: 56px;
        /* 모드 바 높이 보상 */
    }

    .table-container {
        flex-direction: column;
    }

    /* 사이드바 - 접을 수 있는 형태로 변환 */
    .sidebar {
        position: relative;
        width: 100%;
        min-width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        overflow: hidden;
    }

    .sidebar.collapsed {
        max-height: 48px;
    }

    .sidebar-header {
        height: 48px;
        cursor: pointer;
    }

    .sidebar-header::after {
        content: '';
        width: 20px;
        height: 20px;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2378716c'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 01.753 1.659l-4.796 5.48a1 1 0 01-1.506 0z'/%3E%3C/svg%3E");
        background-size: contain;
        background-repeat: no-repeat;
        transition: transform 0.2s ease;
    }

    .sidebar.collapsed .sidebar-header::after {
        transform: rotate(-90deg);
    }

    .tree-container {
        padding: 8px 0;
        max-height: 150px;
        overflow-y: auto;
    }

    .sidebar.collapsed .tree-container {
        display: none;
    }

    /* 테이블 레이아웃 전체 너비 */
    .table-layout {
        border-radius: 0 0 var(--radius-md) var(--radius-md);
        min-height: auto;
    }

    .main-content {
        min-height: calc(100vh - 360px);
    }

    .toolbar {
        height: 48px;
        padding: 0 12px;
    }

    .toolbar h2 {
        max-width: 150px;
        font-size: 14px;
    }

    .solve-header {
        height: 48px;
        padding: 0 12px;
    }

    .table-wrapper {
        padding: 0;
    }

    /* 테이블 셀 터치 최적화 */
    .cell-content {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 14px;
    }

    /* 행 추가 버튼 */
    .add-row-btn {
        padding: 14px;
        font-size: 14px;
    }

    /* 모달 */
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 16px;
    }

    .modal-content.modal-sm {
        max-width: none;
    }
}

/* 모바일 (최대 640px) */
@media (max-width: 640px) {
    .table-main {
        padding: 0 4px;
        padding-top: 64px;
        /* 모드 바 + 여유 */
    }

    .user-table-page {
        --common-header-offset: 56px;
    }

    /* 사이드바 더 컴팩트하게 */
    .sidebar {
        max-height: 180px;
        border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    }

    .sidebar.collapsed {
        max-height: 44px;
    }

    .sidebar-header {
        height: 44px;
        padding: 0 12px;
    }

    .sidebar-header h3 {
        font-size: 13px;
    }

    .tree-node {
        padding: 10px 12px;
    }

    .tree-label {
        font-size: 12px;
    }

    /* 테이블 레이아웃 */
    .table-layout {
        border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    }

    .toolbar {
        height: 44px;
        padding: 0 10px;
    }

    .toolbar h2 {
        font-size: 13px;
        max-width: 120px;
    }

    /* 테이블 헤더 */
    .editable-table th {
        padding: 8px 10px;
        font-size: 12px;
    }

    .editable-table .th-answer {
        padding-right: 60px;
    }

    .table-delete-btn {
        font-size: 10px;
        padding: 3px 6px;
        right: 4px;
    }

    /* 테이블 셀 */
    .cell-content {
        min-height: 48px;
        padding: 12px 10px;
        font-size: 14px;
        line-height: 1.4;
    }

    /* 행 삭제 버튼 */
    .row-delete-btn {
        top: -24px;
        right: 4px;
        padding: 4px 8px;
        font-size: 10px;
    }

    .row-undo-btn {
        top: -28px;
        right: 4px;
        padding: 5px 10px;
        font-size: 10px;
    }

    /* 빈 상태 */
    .empty-state svg {
        width: 48px;
        height: 48px;
    }

    .empty-state p {
        font-size: 13px;
    }

    /* 점수 표시 */
    .score-display {
        padding: 12px;
    }

    .score-card {
        padding: 16px;
    }

    .score-value {
        font-size: 28px;
    }

    /* 모달 전체 화면 */
    .modal-content {
        width: 100%;
        margin: 0;
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        animation: modalSlideUp 0.3s ease-out;
    }

    @keyframes modalSlideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 16px;
        max-height: 50vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 12px 16px;
        border-top: 1px solid var(--border-color);
    }

    .modal-footer .ut-btn {
        flex: 1;
    }

    /* 플로팅 툴바 */
    .floating-toolbar {
        left: 8px !important;
        right: 8px !important;
        width: auto;
        justify-content: center;
    }

    .ftool-btn {
        width: 32px;
        height: 32px;
    }
}

/* 초소형 모바일 (최대 480px) */
@media (max-width: 480px) {
    .table-main {
        padding: 0 2px;
    }

    /* 사이드바 최소화 */
    .sidebar {
        max-height: 160px;
    }

    .tree-node {
        padding: 8px 10px;
    }

    .tree-icon {
        width: 14px;
        height: 14px;
    }

    /* 테이블 */
    .toolbar h2 {
        max-width: 100px;
    }

    .cell-content {
        padding: 10px 8px;
        font-size: 13px;
    }

    /* 온보딩 */
    .tree-onboarding {
        padding: 24px 16px;
    }

    .tree-onboarding-title {
        font-size: 14px;
    }

    .tree-onboarding-desc {
        font-size: 12px;
    }

    .tree-cta-btn {
        padding: 10px 20px;
        font-size: 13px;
    }
}

/* 가로 모드 모바일 */
@media (max-height: 500px) and (max-width: 900px) {
    .mode-toggle-container {
        padding: 4px 8px;
    }

    .sidebar {
        max-height: 120px;
    }

    .modal-content {
        max-height: 95vh;
    }

    .modal-body {
        max-height: 40vh;
    }
}