/* PDF 페이지 편집기 전용 스타일 */

/* 초기 업로드 패널 */
.initial-upload {
    margin-bottom: 20px;
}

.upload-area {
    border: 3px dashed #c5cae9;
    border-radius: 16px;
    padding: 60px 40px;
    text-align: center;
    background: #f8f9ff;
    transition: all 0.3s;
    cursor: pointer;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: #667eea;
    background: #f0f2ff;
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.upload-text {
    font-size: 1.1rem;
    color: #555;
    margin-bottom: 10px;
}

.upload-hint {
    font-size: 0.85rem;
    color: #888;
}

/* 파일 카드 목록 */
.files-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
    padding-left: 64px;  /* 카드 왼쪽 바깥의 단축키 배지 공간 */
}

@media (max-width: 700px) {
    .files-container { padding-left: 0; }
    .file-card-shortcut {
        position: static;
        transform: none;
        display: inline-block;
        margin-right: 8px;
    }
}

.file-card {
    position: relative;
    background: white;
    border-radius: 16px;
    padding: 20px 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: box-shadow 0.2s, opacity 0.2s, filter 0.2s;
    outline: none;
    border: 3px solid transparent;
    opacity: 0.55;
    filter: grayscale(0.25);
}

.file-card:hover {
    opacity: 0.85;
}

.file-card.selected {
    opacity: 1;
    filter: none;
    border-color: #667eea;
    box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);
}

.file-card:focus-visible {
    box-shadow: 0 10px 40px rgba(0,0,0,0.15), 0 0 0 3px rgba(102, 126, 234, 0.35);
}

.file-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 1px solid #eee;
    margin-bottom: 18px;
}

.file-card-info {
    flex: 1;
    min-width: 0;
}

.file-card-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.file-card-name {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

/* 단축키 배지는 파일 카드 왼쪽 바깥에 부착 */
.file-card-shortcut {
    position: absolute;
    top: 50%;
    right: calc(100% + 10px);
    transform: translateY(-50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: #667eea;
    background: white;
    border: 1px solid #c5cae9;
    border-radius: 6px;
    padding: 4px 8px;
    font-family: 'Consolas', 'Monaco', monospace;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.15);
    pointer-events: none;
}

.file-card.selected .file-card-shortcut {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.file-card-meta {
    display: flex;
    gap: 12px;
    margin-top: 4px;
    font-size: 0.85rem;
    color: #888;
}

.file-card-kept {
    color: #11998e;
    font-weight: 600;
}

.file-card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-card-action {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn-add-divider {
    font-size: 0.85rem;
    padding: 0 14px;
}

.btn-move-up,
.btn-move-down {
    background: #eef0fb;
    color: #667eea;
}

.btn-move-up:hover,
.btn-move-down:hover {
    background: #dfe3f7;
}

.btn-move-up:disabled,
.btn-move-down:disabled {
    background: #f5f5f5;
    color: #ccc;
    cursor: not-allowed;
}

.btn-add-divider {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-add-divider:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-add-divider:disabled {
    background: #e0e0e0;
    color: #aaa;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-remove-file {
    background: #fdecea;
    color: #c0392b;
}

.btn-remove-file:hover {
    background: #fad4cf;
}

/* 파일 카드 본문 - 가로 타임라인만 배치 */
.file-card-body {
    padding: 10px 12px 4px;
}

/* 가로 타임라인 */
.page-timeline {
    position: relative;
    padding-top: 34px;  /* 구분선 핸들 + 상단 ✕ 버튼 공간 */
    padding-bottom: 4px;
}

.timeline-track {
    position: relative;
    width: 100%;
    height: 64px;
    background: #f2f2f7;
    border-radius: 10px;
}

.timeline-segments {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    overflow: hidden;
}

.segment {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s;
    user-select: none;
    text-align: center;
    overflow: hidden;
}

.segment:hover {
    filter: brightness(0.95);
}

.segment.keep {
    background: rgba(46, 204, 113, 0.22);
    color: #1e8449;
    border-top: 4px solid #27ae60;
}

.segment.remove {
    background: rgba(231, 76, 60, 0.22);
    color: #a93226;
    border-top: 4px solid #e74c3c;
}

.segment-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: inherit;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.segment-status {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
}

/* 매우 좁은 구간일 때 라벨 숨기고 아이콘만 */
.segment.compact .segment-label {
    display: none;
}

.segment.compact .segment-status {
    font-size: 0.7rem;
}

.segment.tiny .segment-status {
    display: none;
}

/* 구분선 레이어 */
.timeline-dividers {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.divider {
    position: absolute;
    top: -14px;
    bottom: -14px;
    width: 18px;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    pointer-events: auto;
    cursor: ew-resize;
    z-index: 5;
}

.divider-line {
    position: absolute;
    top: 14px;
    bottom: 14px;
    left: 50%;
    width: 4px;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

.divider-handle {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    min-width: 40px;
    height: 16px;
    padding: 0 6px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #667eea;
    font-weight: 700;
    white-space: nowrap;
    z-index: 2;
}

.divider-remove {
    position: absolute;
    top: -26px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: #fdecea;
    color: #c0392b;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 3;
}

.divider-remove:hover {
    background: #f5c6cb;
}

.divider.dragging .divider-line,
.divider.dragging .divider-handle {
    filter: brightness(1.1);
}

/* 타임라인 아래 미리보기 영역 래퍼 (연결선 SVG + 썸네일 그리드) */
.preview-wrap {
    margin-top: 8px;
    display: block;
}

.preview-connectors {
    display: block;
    width: 100%;
    height: 22px;
    overflow: visible;  /* 음수 y(구분선 선 끝까지) 위로 그려도 잘리지 않도록 */
    pointer-events: none;
}

.file-preview {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 140px;
}

.file-preview .preview-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    font-size: 0.9rem;
    text-align: center;
    padding: 20px;
    background: #fafbff;
    border-radius: 10px;
}

.file-preview[data-has-pairs="true"] .preview-empty {
    display: none;
}

.preview-pairs {
    display: none;
    gap: 16px;
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: center;
}

.file-preview[data-has-pairs="true"] .preview-pairs {
    display: flex;
}

/* 썸네일 2장을 한 그룹으로 묶어 점선 테두리로 감쌈. 안쪽 여백 5px로 keep/remove 테두리 간섭 방지 */
.preview-pair {
    display: inline-flex;
    gap: 5px;
    padding: 6px;
    border: 1px dashed #c5cae9;
    border-radius: 10px;
    background: #f8f9ff;
    align-items: stretch;
}

.preview-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: filter 0.15s;
}

.preview-cell:hover {
    filter: brightness(0.97);
}

.preview-caption {
    font-size: 0.72rem;
    white-space: nowrap;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.preview-caption.keep {
    color: #1e8449;
}

.preview-caption.remove {
    color: #a93226;
}

.preview-box {
    position: relative;
    min-height: 80px;
    max-height: var(--thumb-h, 240px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* 삭제 상태: 썸네일 꼭지점끼리 정확히 잇는 빨간 X 표시
   linear-gradient의 방향(to top right / to top left)은 박스의 실제 꼭지점을
   향하므로 가로/세로 비율과 무관하게 대각선이 꼭지점에 정확히 닿는다. */
.preview-box.remove::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to top right,
            transparent calc(50% - 0.75px),
            #e74c3c calc(50% - 0.75px),
            #e74c3c calc(50% + 0.75px),
            transparent calc(50% + 0.75px)),
        linear-gradient(to top left,
            transparent calc(50% - 0.75px),
            #e74c3c calc(50% - 0.75px),
            #e74c3c calc(50% + 0.75px),
            transparent calc(50% + 0.75px));
    pointer-events: none;
    z-index: 2;
}

/* 이미지/캔버스는 PDF 본연의 가로세로 비율을 그대로 유지하고,
   테두리는 박스가 아닌 이미지 자체에 붙여 썸네일에 딱 맞게 표시 */
.preview-box img,
.preview-box canvas {
    display: block;
    max-width: none;
    max-height: var(--thumb-h, 240px);
    width: auto;
    height: auto;
    border: 3px solid transparent;
    border-radius: 4px;
    box-sizing: border-box;
}

.preview-box.keep img,
.preview-box.keep canvas {
    border-color: #27ae60;
}

.preview-box.remove img,
.preview-box.remove canvas {
    border-color: #e74c3c;
}

.preview-box.empty {
    color: #aaa;
    font-size: 0.85rem;
}

/* 눈금 (가로) */
.timeline-ruler {
    position: relative;
    width: 100%;
    height: 26px;
    margin-top: 6px;
    border-top: 1px solid #ddd;
    font-size: 0.72rem;
    color: #888;
}

.ruler-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    padding-top: 6px;
    white-space: nowrap;
    text-align: center;
}

.ruler-tick::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    width: 1px;
    height: 5px;
    background: #bbb;
    transform: translateX(-50%);
}

.ruler-tick.ruler-start,
.ruler-tick.ruler-end {
    color: #555;
    font-weight: 600;
}

/* 파일 추가 영역 */
.file-add-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 20px;
}

.btn-add-file {
    padding: 14px 28px;
    border: 2px dashed #c5cae9;
    border-radius: 12px;
    background: white;
    color: #667eea;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-add-file:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.btn-add-file:disabled {
    border-color: #eee;
    color: #bbb;
    cursor: not-allowed;
    background: #f5f5f5;
}

.file-count-hint {
    font-size: 0.85rem;
    color: #888;
}

/* 병합 옵션 */
.merge-options {
    background: white;
    border-radius: 12px;
    padding: 14px 20px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
    margin: 0 0 20px 64px;  /* 파일 카드와 동일한 왼쪽 정렬 */
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

@media (max-width: 700px) {
    .merge-options { margin-left: 0; }
}

.merge-options .option-label {
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
}

.size-mode-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.size-mode-choice {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 2px solid #e8e8e8;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.88rem;
    color: #666;
    background: #fafbff;
    transition: all 0.2s;
    user-select: none;
}

.size-mode-choice:hover {
    border-color: #c5cae9;
    color: #333;
}

.size-mode-choice input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid #bbb;
    border-radius: 50%;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    background: white;
}

.size-mode-choice input[type="radio"]:checked {
    border-color: #667eea;
    background: #667eea;
    box-shadow: inset 0 0 0 3px white;
}

.size-mode-choice.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12), rgba(118, 75, 162, 0.12));
    color: #4a3aa8;
    font-weight: 600;
}

/* 변환 섹션 */
.convert-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.btn-preview {
    padding: 16px 32px;
    font-size: 1rem;
    border-radius: 12px;
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-preview:hover {
    background: #f0f2ff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.2);
}

.btn-preview:disabled {
    color: #bbb;
    border-color: #ddd;
    cursor: not-allowed;
    background: #f5f5f5;
    transform: none;
    box-shadow: none;
}

.btn-convert:disabled {
    background: #ccc;
    color: white;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* 모달 */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 24px;
}

.modal {
    background: white;
    border-radius: 16px;
    max-width: 1100px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid #eee;
}

.modal-title {
    font-size: 1.15rem;
    color: #333;
    margin: 0;
}

.modal-close {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: none;
    background: #f5f5f5;
    color: #666;
    font-size: 1rem;
    cursor: pointer;
}

.modal-close:hover {
    background: #e8e8e8;
}

.modal-body {
    padding: 20px 24px 24px;
    overflow-y: auto;
}

/* 모달: 병합 미리보기 — 세로 스크롤 시퀀스 (파일 구분 없음) */
.merge-preview-sequence {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.merge-preview-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.merge-preview-page img {
    display: block;
    max-width: 520px;
    max-height: 680px;
    width: auto;
    height: auto;
    border: 3px solid #27ae60;
    border-radius: 6px;
    background: #f5f5f5;
    box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.merge-preview-page-label {
    font-size: 0.85rem;
    color: #555;
    font-weight: 600;
}

.merge-preview-ellipsis {
    font-size: 1.8rem;
    color: #aaa;
    line-height: 0.6;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.merge-preview-empty {
    color: #888;
    font-size: 0.9rem;
    text-align: center;
    padding: 30px 0;
}

/* 진행 상태 */
.progress-container {
    display: none;
    margin: 20px 0 60px;
}

.progress-container.show {
    display: block;
}

.progress-bar {
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    transition: width 0.3s;
    width: 0%;
}

.progress-text {
    text-align: center;
    margin-top: 10px;
    font-size: 0.9rem;
    color: #666;
}
