/**
 * RWC PDF Viewer Styles - Version 2.0.0
 * Clean implementation using PDF.js text layer
 */

/* Modal Container - Override Divi styles */
.rwc-pdf-viewer-modal {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 99999 !important;
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-sizing: border-box !important;
    transform: none !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
}

.rwc-pdf-viewer-modal.show {
    display: block !important;
    opacity: 1 !important;
}

/* Overlay */
.pdf-viewer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
}

/* Container */
.pdf-viewer-container {
    position: relative;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    margin: 5vh auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    z-index: 100000;
}

/* Header */
.pdf-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.pdf-viewer-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    flex: 1;
}

.pdf-viewer-close {
    background: none;
    border: none;
    font-size: 32px;
    line-height: 1;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.pdf-viewer-close:hover {
    background: #e0e0e0;
    color: #333;
}

/* Toolbar */
.pdf-viewer-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    gap: 16px;
    flex-wrap: wrap;
}

.pdf-search-section,
.pdf-nav-section,
.pdf-control-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pdf-search-section {
    flex: 1;
    min-width: 300px;
}

/* Search Input */
.pdf-search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.pdf-search-input:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 1px #0073aa;
}

.search-match-info {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    min-width: 100px;
    text-align: center;
}

.page-info {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    min-width: 100px;
    text-align: center;
}

/* Buttons */
.pdf-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.pdf-btn:hover:not(:disabled) {
    background: #f0f0f0;
    border-color: #999;
}

.pdf-btn:active:not(:disabled) {
    transform: translateY(1px);
}

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

.pdf-btn-primary {
    background: #0073aa;
    color: #fff;
    border-color: #0073aa;
}

.pdf-btn-primary:hover:not(:disabled) {
    background: #005a87;
    border-color: #005a87;
}

.pdf-btn-secondary {
    min-width: 40px;
    padding: 8px 12px;
}

.pdf-btn-secondary span {
    font-size: 16px;
    font-weight: bold;
    display: inline-block;
}

/* Content Area */
.pdf-viewer-content {
    flex: 1;
    overflow: auto;
    background: #525659;
    position: relative;
}

.pdf-viewer-container-inner {
    padding: 20px;
    display: flex;
    justify-content: center;
}

.pdfViewer {
    display: inline-block;
}

/* Page Container - Protected from Divi */
.page {
    margin-bottom: 20px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    background: #fff !important;
    position: relative !important;
    box-sizing: content-box !important;
    padding: 0 !important;
    border: none !important;
    transform: none !important;
}

.canvasWrapper {
    position: relative !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-sizing: content-box !important;
    transform: none !important;
}

.canvasWrapper canvas {
    display: block !important;
    user-select: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-sizing: content-box !important;
}

/* PDF.js Text Layer Styles - Protected from Divi overrides */
.textLayer {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    opacity: 1 !important;
    line-height: 1.0 !important;
    text-align: initial !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-sizing: border-box !important;
    transform: none !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    z-index: 1 !important;
}

.textLayer > span,
.textLayer > br {
    color: transparent !important;
    position: absolute !important;
    white-space: pre !important;
    cursor: text !important;
    transform-origin: 0% 0% !important;
    /* Let PDF.js set all font properties - DO NOT OVERRIDE */
    /* Reset Divi interference only */
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    text-indent: 0 !important;
    vertical-align: baseline !important;
    text-decoration: none !important;
    text-transform: none !important;
    /* Ensure no interference from parent styles */
    float: none !important;
}

/* Default transparent background for non-highlighted spans */
.textLayer > span:not(.highlight) {
    background: transparent !important;
}

/* Ensure proper selection appearance */
.textLayer ::selection {
    background: rgba(0, 100, 255, 0.3);
}

.textLayer ::-moz-selection {
    background: rgba(0, 100, 255, 0.3);
}

.textLayer .highlight {
    margin: -1px !important;
    padding: 1px !important;
    background-color: transparent !important;
    border: 2px solid rgba(50, 205, 50, 0.7) !important;
    border-radius: 4px !important;
    box-sizing: border-box !important;
}

.textLayer .highlight.selected {
    background-color: rgba(144, 238, 144, 0.6) !important;
    border: 2px solid rgba(50, 205, 50, 0.9) !important;
    border-radius: 4px !important;
    box-sizing: border-box !important;
}

/* Loading State */
.pdf-loading-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: #fff;
    font-size: 16px;
}

.pdf-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.pdf-error {
    color: #ff4444;
    text-align: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
}

/* Prevent body scroll when viewer is open */
body.pdf-viewer-open {
    overflow: hidden;
}

/* Responsive Design */
@media (max-width: 768px) {
    .pdf-viewer-container {
        width: 95%;
        height: 95vh;
        margin: 2.5vh auto;
    }

    .pdf-viewer-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .pdf-search-section,
    .pdf-nav-section,
    .pdf-control-section {
        width: 100%;
        justify-content: space-between;
    }

    .pdf-search-section {
        min-width: 0;
    }

    .pdf-viewer-header {
        padding: 16px;
    }

    .pdf-viewer-title {
        font-size: 16px;
    }

    .pdf-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

/* Print styles */
@media print {
    .rwc-pdf-viewer-modal {
        display: none !important;
    }
}
