/* Comparative Viewer */
.comparative-viewer {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 64px - 40px); /* Full height minus nav and padding */
    max-width: 100%;
    margin: 20px;
    width: calc(100% - 40px);
    min-height: 0;
    box-sizing: border-box;
}

/* Override for viewer modal only */
.viewer-modal .modal-content {
    height: calc(100vh - 2rem);
    max-height: calc(100vh - 2rem);
}

.viewer-modal .modal-body {
    padding: 1.5rem 1.5rem 0 1.5rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    flex: 1;
    max-height: none;
}

.viewer-modal .modal-body .comparative-viewer {
    flex: 1;
    margin: 0;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    width: 100%;
}

.viewer-header {
    padding: 0.25rem 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-tertiary);
    flex-shrink: 0;
    margin: 0;
    height: auto;
    min-height: auto;
}

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

.viewer-panels {
    display: flex;
    overflow: hidden;
    margin: 0;
    padding: 0;
    flex: 1;
    min-height: 0;
}

.viewer-panel {
    flex: 1;
    border-right: 1px solid var(--border);
    padding: 4px 4px 0 4px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-bottom: 0;
    height: 100%;
}

.panel-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    padding: 2px 0;
}

.pdf-viewer {
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1;
    min-height: 0;
    border-radius: var(--radius-sm);
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    /* Performance optimization: Enable hardware acceleration */
    will-change: transform;
    transform: translateZ(0);
}

/* PDF Zoom Controls */
.pdf-zoom-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 5;
}

.zoom-btn {
    padding: 6px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 40px;
    justify-content: center;
}

.zoom-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.zoom-btn:active {
    transform: translateY(0);
}

.zoom-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.zoom-percentage {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 45px;
    text-align: center;
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.zoom-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
}

/* PDF Canvas Container */
.pdf-canvas-container {
    flex: 1;
    width: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 8px;
    background: var(--bg-secondary);
}

.pdf-canvas-container canvas {
    transition: transform 0.1s ease;
    background: white;
}

/* Thumbnail rail */
.thumbnail-rail {
    display: flex;
    gap: 8px;
    padding: 8px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.thumbnail-rail .thumb {
    min-width: 80px;
    height: 110px;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    cursor: pointer;
}
.thumbnail-rail .thumb img { width: 100%; height: auto; display:block; }

/* Highlight overlay for PDF regions */
.pdf-highlight-overlay {
    position: absolute;
    border: 2px solid rgba(255, 165, 0, 0.9);
    background: rgba(255, 200, 100, 0.12);
    pointer-events: none;
    border-radius: 2px;
    z-index: 10;
}

.pdf-viewer object,
.pdf-viewer iframe {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
    max-height: 100% !important;
}

/* New viewer layout styles */
.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.viewer-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.viewer-meta { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }

.viewer-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { background: transparent; border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.icon-btn:hover { background: var(--bg-hover); }

.pdf-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px; border-bottom: 1px solid var(--border); background: var(--bg-secondary); }
.pdf-toolbar .pdf-toolbar-left { display:flex; gap:8px; align-items:center; }
.pdf-toolbar .pdf-toolbar-right { display:flex; gap:8px; align-items:center; }

.ocr-toolbar { display:flex; gap:8px; align-items:center; }
.ocr-search { padding:6px 8px; border:1px solid var(--border); border-radius:6px; }

.viewer-footer { display:flex; justify-content:space-between; align-items:center; padding:10px 12px; border-top:1px solid var(--border); background: var(--bg-tertiary); }
.page-controls { display:flex; gap:8px; align-items:center; }
.page-input { width:64px; padding:6px; border:1px solid var(--border); border-radius:6px; }
.footer-actions { display:flex; gap:8px; }

/* Responsive: stack panels on small screens */
@media (max-width: 900px) {
    .viewer-panels { flex-direction: column; }
    .viewer-panel { height: 50vh; }
}

.ocr-text {
    font-family: 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Nanum Gothic', sans-serif;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    color: var(--text-primary);
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    min-height: 0;
    width: 100%;
    margin: 0;
    margin-bottom: 0;
    padding-bottom: 12px;
}

.paragraph {
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
}

.paragraph-number {
    font-weight: 600;
    color: var(--primary);
}

/* OCR Tabs */
.ocr-tabs {
    display: flex;
    gap: 8px;
}

.ocr-tab-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.ocr-tab-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.ocr-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.ocr-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    gap: 0;
    height: 100%;
}

.ocr-tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.ocr-tab-content.active {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

.ocr-json {
    font-family: 'Consolas', 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    color: var(--text-primary);
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    width: 100%;
    min-height: 0;
}

.ocr-download-buttons {
    margin: 0;
    padding: 0.5rem 1rem 0.5rem 1rem;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
}

.download-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: none !important;
    transform: none !important;
    box-shadow: none !important;
}

.download-btn:hover {
    background: var(--primary-dark);
    transform: none !important;
    box-shadow: none !important;
}

.download-btn:active {
    transform: none !important;
    box-shadow: none !important;
}

.download-btn:focus {
    transform: none !important;
    box-shadow: none !important;
    outline: none;
}

.download-btn:active {
    transform: none !important;
    box-shadow: none !important;
}

.page-sync {
    padding: 0.5rem 1rem 0.5rem 1rem;
    border-top: 1px solid var(--border);
    display: flex !important;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-tertiary);
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    margin: 0;
    box-sizing: border-box;
    height: auto !important;
    min-height: auto !important;
    position: relative;
    z-index: 10;
    visibility: visible !important;
    opacity: 1 !important;
}

.page-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.page-btn:hover {
    background: var(--primary-dark);
}

.page-input {
    width: 60px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 13px;
}

/* Modal for Document Viewer */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: calc(100% - 2rem);
    max-width: calc(100% - 2rem);
    height: calc(100vh - 2rem);
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0;
    height: auto;
    min-height: auto;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100% - 50px);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--border);
    color: var(--text-primary);
}


/* Pagination */
.doc-pagination {
    background: white;
    padding: 20px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-top: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.pagination-info {
    font-size: 14px;
    color: var(--text-secondary);
}

.pagination-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pagination-btn {
    background: white;
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    color: var(--text-primary);
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--primary);
    color: var(--primary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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