/**
 * PDF Viewer - Modern Lightweight Viewer
 * Replaces dFlip with a custom PDF.js implementation
 */

.pdf-viewer {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    background: #f8f9fa;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.pdf-viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--crai-green) 0%, #005535 100%);
    color: white;
    flex-wrap: wrap;
}

.pdf-viewer-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 16px;
}

.pdf-viewer-toolbar button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.pdf-viewer-toolbar button:active {
    transform: translateY(0);
}

.pdf-viewer-toolbar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.pdf-page-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 500;
}

.pdf-page-input {
    width: 50px;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}

.pdf-page-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.3);
}

.pdf-page-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

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

.pdf-canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 500px;
    max-height: 80vh;
    overflow: auto;
    background: #525659;
    padding: 20px;
}

.pdf-canvas-wrapper {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
}

.pdf-page-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background: white;
}

.pdf-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: white;
}

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

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

.pdf-loading-text {
    font-size: 14px;
    font-weight: 500;
}

.pdf-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: white;
    padding: 24px;
}

.pdf-error i {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--crai-red);
}

.pdf-error p {
    font-size: 16px;
    margin-bottom: 16px;
}

.pdf-thumbnail-strip {
    display: none;
    gap: 8px;
    padding: 12px;
    background: #2d3035;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.pdf-thumbnail-strip.active {
    display: flex;
}

.pdf-thumbnail {
    flex-shrink: 0;
    width: 80px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.pdf-thumbnail:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.5);
}

.pdf-thumbnail.active {
    opacity: 1;
    border-color: var(--crai-green);
}

/* Fullscreen mode */
.pdf-viewer.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    max-width: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.pdf-viewer.fullscreen .pdf-canvas-container {
    flex: 1;
    max-height: none;
}

/* Double page mode */
.pdf-viewer[data-mode="double"] .pdf-canvas-wrapper {
    gap: 0;
}

.pdf-viewer[data-mode="double"] .pdf-page-canvas:first-child {
    box-shadow: -4px 4px 12px rgba(0, 0, 0, 0.3);
}

.pdf-viewer[data-mode="double"] .pdf-page-canvas:last-child {
    box-shadow: 4px 4px 12px rgba(0, 0, 0, 0.3);
}

/* Touch gestures hint */
.pdf-touch-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pdf-viewer.touch-device .pdf-touch-hint {
    opacity: 1;
    animation: pdf-hint-fade 3s ease-out forwards;
}

@keyframes pdf-hint-fade {
    0%, 70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .pdf-viewer-toolbar {
        padding: 10px 12px;
        gap: 6px;
    }

    .pdf-viewer-toolbar button {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .pdf-page-info {
        font-size: 12px;
        padding: 0 8px;
    }

    .pdf-page-input {
        width: 40px;
        padding: 4px 6px;
        font-size: 12px;
    }

    .pdf-toolbar-divider {
        display: none;
    }

    .pdf-canvas-container {
        min-height: 400px;
        padding: 10px;
    }

    .pdf-thumbnail-strip {
        padding: 8px;
    }

    .pdf-thumbnail {
        width: 60px;
    }
}

@media (max-width: 480px) {
    .pdf-viewer-toolbar button.hide-mobile {
        display: none;
    }

    .pdf-canvas-container {
        min-height: 350px;
    }
}

/* Mobile Volantino Actions */
.volantino-mobile-actions {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    text-align: center;
}

.volantino-mobile-actions .btn {
    width: 100%;
    justify-content: center;
}

/* Hide viewer on mobile, show buttons */
@media (max-width: 768px) {
    .pdf-viewer {
        display: none;
    }

    .show-mobile-only {
        display: flex !important;
    }

    .hide-mobile {
        display: none !important;
    }
}

/* Show viewer on desktop, hide mobile buttons */
@media (min-width: 769px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* Fullscreen mode on mobile - show all controls */
.pdf-viewer.fullscreen {
    display: flex !important;
}

.pdf-viewer.fullscreen .pdf-viewer-toolbar button.hide-mobile {
    display: inline-flex;
}

.pdf-viewer.fullscreen .pdf-toolbar-divider {
    display: block;
}

/* Fullscreen specific styles for mobile */
.pdf-viewer.fullscreen .pdf-canvas-container {
    min-height: auto;
    max-height: none;
    padding: 10px;
}

.pdf-viewer.fullscreen .pdf-page-canvas {
    max-width: 100%;
    max-height: calc(100vh - 80px);
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Close button for fullscreen */
.pdf-viewer.fullscreen .pdf-viewer-toolbar [data-action="fullscreen"] i::before {
    content: "\f00d"; /* FontAwesome times/close icon */
}
