/**
 * MagzPress PDF Viewer - Unified CSS
 * Consolidated styling for PDF viewer functionality
 * Version: 2.0.0 (Unified)
 */

/* ==========================================================================
   CSS Custom Properties / Variables
   ========================================================================== */
:root {
    --overlay-bg: rgba(0, 0, 0, 0.9);
    --overlay-content-bg: #525659;
    --toolbar-bg: #323639;
    --toolbar-text: #fff;
    --toolbar-border: #5f6368;
    --button-hover: rgba(255, 255, 255, 0.08);
    --button-active: rgba(255, 255, 255, 0.16);
    --button-disabled: rgba(255, 255, 255, 0.38);
    --viewer-bg: #525659;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    --border-radius: 4px;
    --toolbar-height: 56px;
    --transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --chrome-blue: #1a73e8;
    --chrome-blue-hover: #1557b0;
}

/* ==========================================================================
   WordPress Integration Styles
   ========================================================================== */


/* WordPress-style PDF viewer buttons */
.magzpress-view-pdf-btn {
    background: #0073aa;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    box-shadow: 0 1px 0 #006799;
}

.magzpress-view-pdf-btn:hover {
    background: #005a87;
    color: white;
    box-shadow: 0 1px 0 #004f7a;
    transform: translateY(-1px);
}

.magzpress-view-pdf-btn:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
    box-shadow: 0 0 0 1px #fff, 0 0 0 3px #0073aa;
}

.magzpress-view-pdf-btn:active {
    transform: translateY(0);
    box-shadow: inset 0 1px 0 #006799;
}

.magzpress-view-pdf-btn .dashicons {
    font-size: 16px;
    line-height: 1;
}

/* PDF container styling */
.magzpress-pdfjs-container {
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    padding: 20px;
    margin: 20px 0;
    text-align: center;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
}

.magzpress-pdfjs-container p {
    margin: 0 0 15px;
    color: #666;
}

/* WordPress admin integration */
.wp-admin .magzpress-view-pdf-btn {
    margin-top: 10px;
}

/* Frontend theme compatibility */
.entry-content .magzpress-pdfjs-container,
.post-content .magzpress-pdfjs-container,
.content .magzpress-pdfjs-container {
    clear: both;
    margin: 20px 0;
}

/* Magazine post type specific */
.single-magazine .magzpress-pdfjs-container {
    background: #f9f9f9;
    border: 2px dashed #ddd;
    margin: 30px 0;
}

.single-magazine .magzpress-view-pdf-btn {
    font-size: 16px;
    padding: 15px 25px;
}

/* Archive page styling */
.archive-magazine .magzpress-view-pdf-btn {
    font-size: 13px;
    padding: 8px 15px;
}

/* Widget area styling */
.widget .magzpress-pdfjs-container {
    padding: 15px;
    margin: 10px 0;
}

.widget .magzpress-view-pdf-btn {
    font-size: 12px;
    padding: 8px 12px;
    width: 100%;
    justify-content: center;
}

/* Loading and error states */
.magzpress-pdfjs-container.loading {
    opacity: 0.7;
    pointer-events: none;
}

.magzpress-pdfjs-container.loading .magzpress-view-pdf-btn {
    background: #ccc;
    cursor: wait;
}

.magzpress-pdfjs-container.error {
    border-color: #dc3232;
    background: #fef7f7;
}

.magzpress-pdfjs-container.error p {
    color: #dc3232;
}

/* Block editor compatibility */
.wp-block .magzpress-pdfjs-container {
    margin: 1em 0;
}

/* ==========================================================================
   PDF Overlay Viewer Styles
   ========================================================================== */

/* Body class for preventing scrolling when overlay is open */
body.magzpress-pdf-overlay-open {
    overflow: hidden;
}

/* Main overlay container - Full viewport coverage */
.magzpress-pdf-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--overlay-bg);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.magzpress-pdf-overlay.active {
    opacity: 1;
    visibility: visible;
}

.magzpress-pdf-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    cursor: pointer;
}

.magzpress-pdf-container {
    width: 100vw;
    height: 100vh;
    background: var(--overlay-content-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    opacity: 0;
    transition: var(--transition);
    position: relative;
    margin: 0 !important;
    padding: 0 !important;
}

.magzpress-pdf-overlay.active .magzpress-pdf-container {
    transform: scale(1);
    opacity: 1;
}

.magzpress-outer-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.magzpress-main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================================
   Toolbar Styles - Chrome PDF Viewer Style
   ========================================================================== */

.magzpress-toolbar-container {
    height: var(--toolbar-height);
    background: var(--toolbar-bg);
    color: var(--toolbar-text);
    flex-shrink: 0;
    border-bottom: 1px solid var(--toolbar-border);
    display: flex;
    align-items: center;
}

.magzpress-toolbar-viewer {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    width: 100%;
}

.magzpress-toolbar-left,
.magzpress-toolbar-middle,
.magzpress-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.magzpress-toolbar-left {
    flex: 1;
}

.magzpress-toolbar-middle {
    flex: 1;
    justify-content: center;
}

.magzpress-toolbar-right {
    flex: 1;
    justify-content: flex-end;
}

.magzpress-toolbar-spacer {
    width: 1px;
    height: 20px;
    background: var(--toolbar-border);
    margin: 0 8px;
}

/* Chrome-style Toolbar Buttons */
.magzpress-toolbar-button {
    background: transparent;
    border: none;
    color: var(--toolbar-text);
    padding: 8px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.magzpress-toolbar-button:hover {
    background: var(--button-hover);
}

.magzpress-toolbar-button:active {
    background: var(--button-active);
}

.magzpress-toolbar-button:disabled {
    color: var(--button-disabled);
    cursor: not-allowed;
}

.magzpress-toolbar-button:disabled:hover {
    background: transparent;
}

.magzpress-toolbar-button span {
    font-size: 16px;
    line-height: 1;
}

/* Navigation arrows - Chrome style */
.magzpress-toolbar-button[title*="Previous"] span {
    transform: rotate(0deg);
}

.magzpress-toolbar-button[title*="Next"] span {
    transform: rotate(0deg);
}

/* Close button - Chrome style */
.magzpress-toolbar-button[title*="Close"] {
    color: #fff;
    font-weight: 500;
}

.magzpress-toolbar-button[title*="Close"] span {
    font-size: 18px;
}

/* Toolbar Field Elements - Chrome Style */
.magzpress-toolbar-field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.08);
    padding: 4px 12px;
    border-radius: 16px;
    border: 1px solid transparent;
}

.magzpress-page-input {
    background: transparent;
    border: none;
    color: var(--toolbar-text);
    padding: 4px 8px;
    border-radius: 4px;
    width: 50px;
    text-align: center;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

.magzpress-toolbar-label {
    font-size: 13px;
    opacity: 0.87;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Zoom Controls - Chrome Style */
.magzpress-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.magzpress-scale-select {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--toolbar-text);
    padding: 6px 12px;
    border-radius: var(--border-radius);
    font-size: 13px;
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-width: 120px;
}

.magzpress-scale-select:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--chrome-blue);
}

.magzpress-scale-select option {
    background: #2d3033;
    color: #fff;
}

/* ==========================================================================
   PDF Viewer Content Styles - Chrome PDF Viewer Style
   ========================================================================== */

.magzpress-viewer-container {
    flex: 1;
    background: var(--viewer-bg);
    overflow: auto;
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
}

.magzpress-pdf-viewer {
    display: block;
    width: max-content;
    min-width: 100%;
    padding: 0;
    min-height: 100%;
    margin: 0;
    position: relative;
}

/* PDF Pages - Chrome Style Layout */
.magzpress-pdf-page {
    margin: 0 auto 20px auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
    overflow: hidden;
    background: #fff;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: fit-content;
    /* Ensure proper aspect ratio maintenance */
    line-height: 0;
    /* Click navigation styling */
    cursor: pointer;
    transition: var(--transition);
}

.magzpress-pdf-page:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: translateY(-1px);
}

/* Click navigation areas - subtle visual hint */
.magzpress-pdf-page::before,
.magzpress-pdf-page::after {
    content: '';
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 1;
}

.magzpress-pdf-page::before {
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.1), transparent);
    border-radius: 2px 0 0 2px;
}

.magzpress-pdf-page::after {
    right: 0;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.1), transparent);
    border-radius: 0 2px 2px 0;
}

.magzpress-pdf-page:hover::before,
.magzpress-pdf-page:hover::after {
    opacity: 1;
}

.magzpress-pdf-page:last-child {
    margin-bottom: 20px;
}

.magzpress-pdf-page-canvas {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    background: #fff;
    /* Ensure canvas preserves aspect ratio */
    object-fit: contain;
    /* Smooth rendering for better quality */
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
}

.magzpress-pdf-page-error {
    padding: 20px;
    color: #d93025;
    text-align: center;
    background: #fce8e6;
    border: 1px solid #d93025;
    border-radius: 4px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0 auto 20px auto;
    max-width: 400px;
}

/* ==========================================================================
   Loading and Progress Indicators
   ========================================================================== */

.magzpress-loading-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.magzpress-progress {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    width: 0%;
    transition: width 0.3s ease;
}

/* ==========================================================================
   Password Dialog
   ========================================================================== */

.magzpress-password-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    z-index: 1001;
    min-width: 320px;
    border: none;
}

.magzpress-dialog-content h3 {
    margin: 0 0 16px 0;
    color: #333;
    font-size: 18px;
}

.magzpress-dialog-content p {
    margin: 0 0 16px 0;
    color: #666;
}

.magzpress-password-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 4px;
    font-size: 16px;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.magzpress-password-input:focus {
    outline: none;
    border-color: #667eea;
}

.magzpress-dialog-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ==========================================================================
   Error Messages
   ========================================================================== */

.magzpress-pdf-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #e74c3c;
    text-align: center;
    padding: 40px;
}

.magzpress-pdf-error .error-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.7;
}

.magzpress-pdf-error .error-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.magzpress-pdf-error .error-message {
    font-size: 16px;
    opacity: 0.8;
    max-width: 400px;
    line-height: 1.5;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .magzpress-view-pdf-btn {
        display: block;
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    .magzpress-pdfjs-container {
        padding: 15px;
        margin: 15px 0;
    }

    .magzpress-pdf-container {
        width: 100vw;
        height: 100vh;
    }

    .magzpress-toolbar-viewer {
        padding: 0 10px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .magzpress-toolbar-left,
    .magzpress-toolbar-middle,
    .magzpress-toolbar-right {
        flex: none;
        gap: 8px;
    }

    .magzpress-toolbar-button {
        min-width: 32px;
        height: 32px;
        padding: 6px 8px;
        font-size: 12px;
    }

    .magzpress-page-input {
        width: 50px;
        font-size: 12px;
    }

    .magzpress-scale-select {
        font-size: 12px;
        padding: 4px 6px;
    }

    .magzpress-pdf-viewer {
        padding: 10px;
    }

    .magzpress-pdf-page {
        margin: 0 auto 15px auto;
        /* Enhanced mobile click feedback */
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    .magzpress-pdf-page-canvas {
        max-width: calc(100vw - 20px);
        height: auto;
    }

    .magzpress-password-dialog {
        width: 90vw;
        max-width: 320px;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .magzpress-toolbar-container {
        height: auto;
        min-height: var(--toolbar-height);
    }

    .magzpress-toolbar-viewer {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        gap: 10px;
    }

    .magzpress-toolbar-left,
    .magzpress-toolbar-middle,
    .magzpress-toolbar-right {
        justify-content: center;
        flex-wrap: wrap;
    }

    .magzpress-toolbar-field {
        justify-content: center;
    }
}

/* ==========================================================================
   Accessibility and High Contrast Support
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .magzpress-view-pdf-btn {
        border: 2px solid currentColor;
        background: ButtonFace;
        color: ButtonText;
    }

    .magzpress-pdfjs-container {
        border: 2px solid ButtonText;
        background: Canvas;
        color: CanvasText;
    }

    .magzpress-toolbar-button {
        border: 2px solid currentColor;
    }
}

/* Dark mode support for themes that use it */
@media (prefers-color-scheme: dark) {
    .magzpress-pdfjs-container {
        background: #1e1e1e;
        border-color: #333;
        color: #e0e0e0;
    }

    .magzpress-pdfjs-container p {
        color: #bbb;
    }

    .magzpress-password-dialog {
        background: #2d2d2d;
        color: #e0e0e0;
    }

    .magzpress-dialog-content h3 {
        color: #fff;
    }

    .magzpress-dialog-content p {
        color: #bbb;
    }

    .magzpress-password-input {
        background: #3d3d3d;
        border-color: #4d4d4d;
        color: #e0e0e0;
    }
}

/* Focus indicators for keyboard navigation */
.magzpress-toolbar-button:focus,
.magzpress-page-input:focus,
.magzpress-scale-select:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    .magzpress-pdf-overlay,
    .magzpress-pdf-container,
    .magzpress-toolbar-button,
    .magzpress-view-pdf-btn,
    .magzpress-progress {
        transition: none;
    }
}