/* PDF Viewer với chặn download hoàn hảo - Layout đơn giản */
.pdf-viewer-secure {
    position: relative;
    width: 100%;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid #e0e0e0;
}

.pdf-content {
    padding: 20px;
}

/* PDF Canvas Container - Responsive cho mọi thiết bị */
#pdf-viewer-container {
    position: relative;
    background: #f5f5f5;
    border-radius: 8px;
    overflow: auto; /* allow scroll when page is taller */
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
    display: flex;
    justify-content: center;
    align-items: flex-start; /* align page to top for vertical documents */
    padding: 12px; /* small padding for comfortable scroll */
    width: 100%;
    height: clamp(300px, 65vh, 900px); /* dynamic height */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: #c2a3c9 #eee; /* track thumb colors */
    cursor: grab;
}
#pdf-viewer-container.dragging {
	cursor: grabbing;
}

#pdf-viewer-container::-webkit-scrollbar {
	width: 8px;  /* vertical thickness */
	height: 8px; /* horizontal thickness (same as vertical) */
}
#pdf-viewer-container::-webkit-scrollbar-track {
	background: #eee;
	border-radius: 4px;
}
#pdf-viewer-container::-webkit-scrollbar-thumb {
	background: #c2a3c9; /* match UI color */
	border-radius: 4px;
}
#pdf-viewer-container::-webkit-scrollbar-thumb:hover {
	background: #a67fb1;
}

/* PDF Scroll Wrapper - Cho mobile zoom */
#pdf-scroll-wrapper {
    width: 100%;
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
    position: relative;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    /* Đảm bảo scroll ngang hoạt động */
    white-space: nowrap;
}

/* Canvas trong wrapper - không bị bẹt */
#pdf-scroll-wrapper #pdf-canvas {
    margin: 0;
    display: block;
    max-width: none !important;
    max-height: none !important;
    width: auto !important;
    height: auto !important;
    /* Đảm bảo tỷ lệ khung hình */
    object-fit: contain;
}

/* Canvas chính - khi không có wrapper */
#pdf-canvas {
    max-width: 100%;
    height: auto;
    background: transparent; /* Tắt nền trắng */
    box-shadow: none; /* Tắt bóng */
    display: block;
    margin: auto !important; /* Căn giữa */
}

/* Loading message */
#pdf-canvas:empty::before {
    content: "Đang tải...";
    display: block;
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 16px;
    font-weight: 500;
}

/* PDF Controls - Layout mới với zoom ở giữa */
.pdf-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    gap: 20px;
    margin-top: 20px;
}

.pdf-control-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.pdf-control-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    white-space: nowrap;
    min-width: 120px;
}

.pdf-control-btn .btn-icon {
    display: none !important;
}

.pdf-control-btn:hover {
    background: #0056b3;
}

.pdf-control-btn:active {
    background: #004085;
    transform: translateY(1px);
}

.pdf-control-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.pdf-page-info {
    font-size: 14px;
    color: #666;
    font-weight: 500;
    text-align: center;
}

/* Zoom Controls - Ở giữa */
.pdf-zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pdf-zoom-btn {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #e0e0e0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.pdf-zoom-btn:hover {
    background: #e9ecef;
    border-color: #007bff;
    color: #007bff;
}

.pdf-zoom-btn:active {
    transform: scale(0.95);
}

.pdf-zoom-level {
    font-size: 12px;
    color: #666;
    font-weight: 500;
    min-width: 45px;
    text-align: center;
}

/* Fallback message */
.pdf-fallback-message {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.pdf-fallback-message p {
    margin: 10px 0;
    font-size: 16px;
}

/* Loading và Error States */
.pdf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #666;
}

.pdf-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.pdf-error {
    text-align: center;
    padding: 40px 20px;
    color: #dc3545;
}

.pdf-error-icon {
    font-size: 48px;
    margin-bottom: 20px;
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    #pdf-viewer-container {
        -webkit-overflow-scrolling: touch;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }

    #pdf-canvas {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    .pdf-control-btn,
    .pdf-zoom-btn {
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .pdf-viewer-secure {
        margin: 10px;
        border-radius: 6px;
    }

    .pdf-content {
        padding: 15px;
    }

    #pdf-viewer-container {
        height: clamp(220px, 55vh, 620px);
        border-radius: 6px;
        overflow: hidden; /* Ẩn scroll của container chính */
    }
    
    /* Khi zoom > 100%, cho phép scroll ngang và dọc */
    #pdf-viewer-container.zoomed {
        overflow: hidden;
        justify-content: flex-start;
        align-items: flex-start;
    }
    
    #pdf-scroll-wrapper {
        width: 100%;
        height: 100%;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: #007bff #f0f0f0;
        /* Đảm bảo scroll ngang */
        white-space: nowrap;
        position: relative;
    }
    
    /* Custom scrollbar cho mobile */
    #pdf-scroll-wrapper::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }
    
    #pdf-scroll-wrapper::-webkit-scrollbar-track {
        background: #f0f0f0;
        border-radius: 4px;
    }
    
    #pdf-scroll-wrapper::-webkit-scrollbar-thumb {
        background: #007bff;
        border-radius: 4px;
    }
    
    #pdf-scroll-wrapper::-webkit-scrollbar-thumb:hover {
        background: #0056b3;
    }
    
    /* Canvas trong wrapper - không bị bẹt */
    #pdf-scroll-wrapper #pdf-canvas {
        margin: 0;
        display: block;
        max-width: none !important;
        max-height: none !important;
        width: auto !important;
        height: auto !important;
        /* Đảm bảo tỷ lệ khung hình */
        object-fit: contain;
        /* Cho phép scroll ngang */
        white-space: nowrap;
    }

    .pdf-controls {
        flex-direction: row !important;
        justify-content: center;
        gap: 15px;
        padding: 15px;
    }

    .pdf-control-center {
        order: unset !important;
        margin-bottom: 0 !important;
        width: fit-content;
        flex: unset;
    }

    .pdf-control-btn {
        width: 5rem !important;
        height: 5rem !important;
        min-width: unset !important;
        padding: 0 !important;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .pdf-zoom-controls {
        padding: 6px 10px;
    }

    .pdf-zoom-btn {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }

    .pdf-zoom-level {
        font-size: 11px;
        min-width: 40px;
    }

    .pdf-control-btn .btn-icon {
        display: block !important;
    }

    .pdf-control-btn .btn-text {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .pdf-viewer-secure {
        margin: 5px;
    }

    #pdf-viewer-container {
        height: clamp(180px, 50vh, 540px);
    }

    .pdf-controls {
        padding: 12px;
    }

    .pdf-control-btn {
        padding: 15px 20px;
        font-size: 18px;
    }

    .pdf-zoom-controls {
        padding: 8px 12px;
    }
}

/* Touch Device Optimization */
@media (hover: none) and (pointer: coarse) {

    .pdf-control-btn,
    .pdf-zoom-btn {
        min-height: 44px;
        /* iOS minimum touch target */
    }

    .pdf-controls {
        gap: 20px;
        /* Larger gap for touch */
    }
}

/* High DPI Display Support */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    #pdf-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #pdf-viewer-container {
        height: clamp(160px, 45vh, 500px);
    }

    .pdf-controls {
        flex-direction: row;
        gap: 15px;
    }

    .pdf-control-btn {
        width: auto;
        max-width: none;
    }

    .pdf-control-center {
        order: 0;
        margin-bottom: 0;
    }
}

/* Desktop Large Screens */
@media (min-width: 1200px) {
    #pdf-viewer-container {
        height: clamp(300px, 70vh, 1000px);
    }

    .pdf-controls {
        padding: 20px 30px;
    }

    .pdf-control-btn {
        padding: 12px 24px;
        font-size: 16px;
    }

    .pdf-zoom-controls {
        padding: 10px 15px;
    }

    .pdf-zoom-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
}

/* Print Styles */
@media print {
    .pdf-controls {
        display: none;
    }

    #pdf-viewer-container {
        height: auto;
        min-height: auto;
    }

    #pdf-canvas {
        max-width: none;
        height: auto;
    }
}