:root {
    --primary-color: #FF4F38;
    --secondary-color: #3282FB;
    --dark-bg: rgba(0, 0, 0, 0.85);
    --light-bg: rgba(255, 255, 255, 0.95);
    --transition: all 0.2s ease;
    --border-radius: 25px;
    --control-padding: 10px;
    --control-gap: 8px;
}

/* PDF Viewer Container */
#pdf-viewer-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
}

@media (max-width: 768px) {
    #pdf-viewer-container {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    #pdf-viewer-container {
        padding: 10px;
    }
}

#pdf-render {
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    width: 100%;
    height: auto;
    background: #fff;
    display: block;
    max-width: 100%;
}

/* Loading State */
.pdf-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    background: var(--light-bg);
    padding: 16px 24px;
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: none;
    align-items: center;
    font-size: 15px;
    color: var(--primary-color);
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.3);
    white-space: nowrap;
}

.pdf-loading.show {
    display: flex;
}

.pdf-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 79, 56, 0.3);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
    flex-shrink: 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.pdf-error {
    text-align: center;
    padding: 40px 20px;
    color: #dc3545;
    background: #f8f9fa;
    border-radius: 12px;
    margin: 20px 0;
    border: 1px solid #f5c6cb;
}

.pdf-error h3 {
    margin-bottom: 12px;
    font-size: 1.25rem;
}

.pdf-error p {
    margin-bottom: 20px;
    color: #721c24;
}

.pdf-error > div {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .pdf-error {
        padding: 30px 15px;
    }
    
    .pdf-error > div {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
}

.pdf-error-state #pdf-render,
.pdf-error-state #pdf-controls,
.pdf-error-state #pdf-controls-fullscreen {
    display: none !important;
}

/* Base Controls Styling - Completely Redesigned for Consistency */
.pdf-controls,
.pdf-controls-fullscreen {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    
    /* Consistent container styling */
    background: var(--light-bg);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    
    /* Flexible layout */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--control-gap);
    padding: var(--control-padding);
    
    /* Responsive sizing */
    min-width: 280px;
    max-width: calc(100vw - 40px);
    
    /* Smooth transitions */
    opacity: 0;
    visibility: hidden;
    transition: var(--transition), transform 0.3s ease;
}

/* Fullscreen specific styling */
.pdf-controls-fullscreen {
    background: var(--dark-bg);
    border-color: rgba(255, 255, 255, 0.2);
    z-index: 2147483647;
    display: none;
}

.pdf-controls-fullscreen .page-info,
.pdf-controls-fullscreen .zoom-value {
    color: #ffffff !important;
}

/* Visible state */
.pdf-controls.visible,
.pdf-controls-fullscreen.visible {
    opacity: 1;
    visibility: visible;
}

/* Responsive Controls Layout */
@media (max-width: 992px) {
    .pdf-controls,
    .pdf-controls-fullscreen {
        min-width: 260px;
        padding: 9px;
        gap: 7px;
    }
}

@media (max-width: 768px) {
    .pdf-controls,
    .pdf-controls-fullscreen {
        bottom: 16px;
        min-width: 240px;
        max-width: calc(100vw - 32px);
        padding: 8px;
        gap: 6px;
        border-radius: 20px;
    }
}

@media (max-width: 480px) {
    .pdf-controls,
    .pdf-controls-fullscreen {
        bottom: 12px;
        min-width: 200px;
        max-width: calc(100vw - 24px);
        padding: 8px;
        gap: 4px;
        border-radius: 18px;
    }
}

@media (max-width: 360px) {
    .pdf-controls,
    .pdf-controls-fullscreen {
        min-width: unset;
        width: calc(100vw - 20px);
        flex-wrap: wrap;
        justify-content: center;
        padding: 10px;
        gap: 8px;
        border-radius: 16px;
    }
}

/* Unified Button Styling - Completely Consistent */
.pdf-controls button,
.pdf-controls-fullscreen button,
.pdf-controls a.control-btn,
.pdf-controls-fullscreen a.control-btn,
.pdf-error .th-btn {
    /* Reset and base styling */
    all: unset;
    box-sizing: border-box;
    
    /* Consistent appearance */
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Consistent sizing - FIXED */
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    
    /* Consistent styling */
    background: var(--primary-color);
    color: #ffffff;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    
    /* Consistent interaction */
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    
    /* Prevent shrinking */
    flex-shrink: 0;
}

/* Download button variant */
.pdf-controls .download-btn,
.pdf-controls-fullscreen .download-btn {
    background: var(--secondary-color);
}

/* Error button styling */
.pdf-error .th-btn {
    width: auto;
    height: auto;
    min-width: 120px;
    padding: 12px 20px;
    border-radius: var(--border-radius);
    white-space: nowrap;
}

/* Responsive button sizing */
@media (max-width: 768px) {
    .pdf-controls button,
    .pdf-controls-fullscreen button,
    .pdf-controls a.control-btn,
    .pdf-controls-fullscreen a.control-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-radius: 19px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .pdf-controls button,
    .pdf-controls-fullscreen button,
    .pdf-controls a.control-btn,
    .pdf-controls-fullscreen a.control-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        border-radius: 18px;
        font-size: 12px;
    }
}

/* Interactive States */
.pdf-controls button:hover,
.pdf-controls-fullscreen button:hover,
.pdf-controls a.control-btn:hover,
.pdf-controls-fullscreen a.control-btn:hover,
.pdf-error .th-btn:hover {
    background: #e63e2a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 79, 56, 0.3);
}

.pdf-controls .download-btn:hover,
.pdf-controls-fullscreen .download-btn:hover {
    background: #2970e6;
    box-shadow: 0 4px 12px rgba(50, 130, 251, 0.3);
}

.pdf-controls button:active,
.pdf-controls-fullscreen button:active,
.pdf-controls a.control-btn:active,
.pdf-controls-fullscreen a.control-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.pdf-controls button:disabled,
.pdf-controls-fullscreen button:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.pdf-controls button:disabled:hover,
.pdf-controls-fullscreen button:disabled:hover {
    background: #cccccc;
    transform: none;
    box-shadow: none;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .pdf-controls button:hover,
    .pdf-controls-fullscreen button:hover,
    .pdf-controls a.control-btn:hover,
    .pdf-controls-fullscreen a.control-btn:hover {
        transform: none;
        box-shadow: none;
    }
    
    .pdf-controls button:hover {
        background: var(--primary-color);
    }
    
    .pdf-controls .download-btn:hover,
    .pdf-controls-fullscreen .download-btn:hover {
        background: var(--secondary-color);
    }
    
    /* Enhanced touch targets */
    .pdf-controls button,
    .pdf-controls-fullscreen button,
    .pdf-controls a.control-btn,
    .pdf-controls-fullscreen a.control-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Page Info Styling - Consistent */
.pdf-controls .page-info,
.pdf-controls-fullscreen .page-info {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 600;
    color: #333333;
    white-space: nowrap;
    flex-shrink: 0;
    height: 40px;
    line-height: 1;
}

.pdf-controls-fullscreen .page-info {
    color: #ffffff;
}

@media (max-width: 768px) {
    .pdf-controls .page-info,
    .pdf-controls-fullscreen .page-info {
        padding: 0 10px;
        font-size: 13px;
        height: 38px;
    }
}

@media (max-width: 480px) {
    .pdf-controls .page-info,
    .pdf-controls-fullscreen .page-info {
        padding: 0 8px;
        font-size: 12px;
        height: 36px;
    }
}

@media (max-width: 360px) {
    .pdf-controls .page-info,
    .pdf-controls-fullscreen .page-info {
        width: 100%;
        order: -1;
        margin-bottom: 4px;
        height: auto;
        padding: 8px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 12px;
        text-align: center;
    }
}

/* Zoom Controls - Consistent Layout */
.pdf-controls .zoom-controls,
.pdf-controls-fullscreen .zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.pdf-controls-fullscreen .zoom-controls {
    border-left-color: rgba(255, 255, 255, 0.3);
}

.pdf-controls .zoom-value,
.pdf-controls-fullscreen .zoom-value {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    height: 40px;
    font-size: 12px;
    font-weight: 600;
    color: #666666;
    text-align: center;
    flex-shrink: 0;
}

.pdf-controls-fullscreen .zoom-value {
    color: #ffffff;
}

@media (max-width: 768px) {
    .pdf-controls .zoom-controls,
    .pdf-controls-fullscreen .zoom-controls {
        gap: 4px;
        margin-left: 6px;
        padding-left: 6px;
    }
    
    .pdf-controls .zoom-value,
    .pdf-controls-fullscreen .zoom-value {
        min-width: 45px;
        height: 38px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .pdf-controls .zoom-controls,
    .pdf-controls-fullscreen .zoom-controls {
        gap: 3px;
        margin-left: 4px;
        padding-left: 4px;
    }
    
    .pdf-controls .zoom-value,
    .pdf-controls-fullscreen .zoom-value {
        min-width: 40px;
        height: 36px;
        font-size: 10px;
    }
}

@media (max-width: 360px) {
    .pdf-controls .zoom-controls,
    .pdf-controls-fullscreen .zoom-controls {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        width: 100%;
        justify-content: center;
        order: 1;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding-top: 8px;
        margin-top: 4px;
    }
    
    .pdf-controls-fullscreen .zoom-controls {
        border-top-color: rgba(255, 255, 255, 0.3);
    }
}

/* Fullscreen States */
#pdf-viewer-container:fullscreen .pdf-controls {
    display: none !important;
}

#pdf-viewer-container:fullscreen .pdf-controls-fullscreen {
    display: flex !important;
}

#pdf-viewer-container:fullscreen {
    background: #2c2c2c;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 20px;
}

@media (max-width: 768px) {
    #pdf-viewer-container:fullscreen {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    #pdf-viewer-container:fullscreen {
        padding: 10px;
    }
}

#pdf-viewer-container:fullscreen #pdf-render {
    margin: 20px auto;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

/* Landscape orientation optimizations */
@media (max-height: 500px) and (orientation: landscape) {
    .pdf-controls,
    .pdf-controls-fullscreen {
        bottom: 8px;
        padding: 6px;
        gap: 4px;
    }
    
    .pdf-controls button,
    .pdf-controls-fullscreen button,
    .pdf-controls a.control-btn,
    .pdf-controls-fullscreen a.control-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
    }
    
    .pdf-controls .page-info,
    .pdf-controls-fullscreen .page-info {
        height: 34px;
        font-size: 11px;
        padding: 0 6px;
    }
    
    .pdf-controls .zoom-value,
    .pdf-controls-fullscreen .zoom-value {
        height: 34px;
        min-width: 35px;
        font-size: 9px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .pdf-controls,
    .pdf-controls-fullscreen {
        border-width: 0.5px;
    }
    
    .pdf-loading {
        border-width: 0.5px;
    }
}