/**
 * Tewido PDF Viewer Widget - Flip Book Style
 */

/* ========================================
   Grid Layout
   ======================================== */

.tewido-pdf-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

/* Card Styles */
.tewido-pdf-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.tewido-pdf-card:hover {
    transform: translateY(-4px);
}

/* Cover Image */
.tewido-pdf-cover {
    position: relative;
    overflow: hidden;
    aspect-ratio: 4/3;
    background-color: #f3f4f6;
}

.dark .tewido-pdf-cover {
    background-color: #374151;
}

.tewido-pdf-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.tewido-pdf-card:hover .tewido-pdf-cover img {
    transform: scale(1.05);
}

/* Content */
.tewido-pdf-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.tewido-pdf-title {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.4;
    margin: 0 0 8px 0;
}

.tewido-pdf-desc {
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0 0 16px 0;
    flex: 1;
}

/* Open Button */
.tewido-pdf-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    border: none;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.2s ease;
    margin-top: auto;
}

.tewido-pdf-open:hover {
    transform: translateY(-1px);
}

.tewido-pdf-open:active {
    transform: translateY(0);
}

.tewido-pdf-icon {
    flex-shrink: 0;
}

.tewido-pdf-no-file {
    display: inline-block;
    font-size: 0.875rem;
    color: #9ca3af;
    font-style: italic;
    margin-top: auto;
}

/* ========================================
   Full Screen Modal
   ======================================== */

.tewido-pdf-modal.tewido-pdf-flipbook {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: none;
    flex-direction: column;
    padding: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.tewido-pdf-modal.tewido-pdf-flipbook.active {
    display: flex;
}

.tewido-pdf-flipbook .tewido-pdf-modal-overlay {
    display: none;
}

/* Header */
.tewido-pdf-flipbook .tewido-pdf-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    z-index: 10;
}

.tewido-pdf-flipbook .tewido-pdf-modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #f9fafb;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tewido-pdf-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tewido-pdf-flipbook .tewido-pdf-zoom {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
}

.tewido-pdf-flipbook .tewido-pdf-zoom-level {
    font-size: 0.75rem;
    color: #9ca3af;
    min-width: 45px;
    text-align: center;
}

.tewido-pdf-flipbook .tewido-pdf-zoom-in,
.tewido-pdf-flipbook .tewido-pdf-zoom-out {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background-color: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.tewido-pdf-flipbook .tewido-pdf-zoom-in:hover,
.tewido-pdf-flipbook .tewido-pdf-zoom-out:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.tewido-pdf-flipbook .tewido-pdf-download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    border-radius: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.tewido-pdf-flipbook .tewido-pdf-download-btn:hover {
    background-color: #3b82f6;
    color: #ffffff;
}

.tewido-pdf-flipbook .tewido-pdf-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background-color: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.tewido-pdf-flipbook .tewido-pdf-modal-close:hover {
    background-color: #ef4444;
    color: #ffffff;
}

/* ========================================
   Book Layout
   ======================================== */

.tewido-pdf-book-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 20px;
    overflow: hidden;
    position: relative;
}

/* Navigation Arrows */
.tewido-pdf-nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: none;
    background-color: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
    flex-shrink: 0;
    z-index: 5;
}

.tewido-pdf-nav-arrow:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transform: scale(1.1);
}

.tewido-pdf-nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

/* Book Container */
.tewido-pdf-book {
    display: flex;
    align-items: stretch;
    justify-content: center;
    max-width: calc(100% - 160px);
    max-height: 100%;
    position: relative;
}

/* Loading State */
.tewido-pdf-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: #9ca3af;
    font-size: 0.875rem;
    z-index: 20;
    background: rgba(15, 23, 42, 0.9);
    border-radius: 8px;
}

.tewido-pdf-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: tewido-pdf-spin 0.8s linear infinite;
}

@keyframes tewido-pdf-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Pages */
.tewido-pdf-page {
    position: relative;
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.tewido-pdf-page-left {
    border-radius: 4px 0 0 4px;
    box-shadow:
        inset -30px 0 40px -20px rgba(0, 0, 0, 0.15),
        -2px 0 10px rgba(0, 0, 0, 0.2);
}

.tewido-pdf-page-right {
    border-radius: 0 4px 4px 0;
    box-shadow:
        inset 30px 0 40px -20px rgba(0, 0, 0, 0.15),
        2px 0 10px rgba(0, 0, 0, 0.2);
}

/* Book Spine */
.tewido-pdf-spine {
    width: 8px;
    background: linear-gradient(90deg,
        #1f2937 0%,
        #374151 20%,
        #4b5563 50%,
        #374151 80%,
        #1f2937 100%
    );
    flex-shrink: 0;
    box-shadow:
        inset 0 0 10px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(0, 0, 0, 0.3);
    z-index: 2;
}

/* Canvas */
.tewido-pdf-flipbook .tewido-pdf-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    transition: opacity 0.3s ease;
}

/* Page Numbers */
.tewido-pdf-page-number {
    position: absolute;
    bottom: 12px;
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 500;
}

.tewido-pdf-page-num-left {
    left: 16px;
}

.tewido-pdf-page-num-right {
    right: 16px;
}

/* ========================================
   Page Slide Transitions
   ======================================== */

/* Slide animation for page turns */
.tewido-pdf-page {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Next page - slides from right */
.tewido-pdf-page-right.slide-out-left {
    transform: translateX(-30px);
    opacity: 0;
}

.tewido-pdf-page-left.slide-out-left {
    transform: translateX(-30px);
    opacity: 0;
}

/* Previous page - slides from left */
.tewido-pdf-page-right.slide-out-right {
    transform: translateX(30px);
    opacity: 0;
}

.tewido-pdf-page-left.slide-out-right {
    transform: translateX(30px);
    opacity: 0;
}

/* Canvas fade */
.tewido-pdf-canvas {
    transition: opacity 0.25s ease;
}

.tewido-pdf-canvas.fading {
    opacity: 0 !important;
}

/* ========================================
   Footer Controls
   ======================================== */

.tewido-pdf-flipbook .tewido-pdf-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.tewido-pdf-flipbook .tewido-pdf-page-info {
    font-size: 0.875rem;
    color: #9ca3af;
}

.tewido-pdf-flipbook .tewido-pdf-current-page {
    color: #ffffff;
    font-weight: 600;
    margin: 0 4px;
}

/* ========================================
   Responsive - Tablet
   ======================================== */

@media (max-width: 1024px) {
    .tewido-pdf-book-wrapper {
        padding: 16px;
        gap: 12px;
    }

    .tewido-pdf-nav-arrow {
        width: 44px;
        height: 44px;
    }

    .tewido-pdf-book {
        max-width: calc(100% - 120px);
    }
}

/* ========================================
   Responsive - Mobile
   ======================================== */

@media (max-width: 768px) {
    .tewido-pdf-flipbook .tewido-pdf-modal-header {
        padding: 10px 16px;
    }

    .tewido-pdf-flipbook .tewido-pdf-modal-title {
        font-size: 0.875rem;
        max-width: 120px;
    }

    .tewido-pdf-flipbook .tewido-pdf-zoom {
        display: none;
    }

    .tewido-pdf-book-wrapper {
        padding: 12px 8px;
        gap: 8px;
    }

    .tewido-pdf-nav-arrow {
        width: 40px;
        height: 40px;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        background-color: rgba(0, 0, 0, 0.5);
    }

    .tewido-pdf-nav-arrow.tewido-pdf-prev {
        left: 8px;
    }

    .tewido-pdf-nav-arrow.tewido-pdf-next {
        right: 8px;
    }

    .tewido-pdf-nav-arrow:hover {
        transform: translateY(-50%) scale(1.1);
    }

    .tewido-pdf-book {
        max-width: 100%;
        flex-direction: column;
    }

    /* Single page view on mobile */
    .tewido-pdf-page-left {
        display: none;
    }

    .tewido-pdf-spine {
        display: none;
    }

    .tewido-pdf-page-right {
        border-radius: 4px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }

    .tewido-pdf-flipbook .tewido-pdf-controls {
        padding: 10px 16px;
    }
}

/* ========================================
   Load More Button
   ======================================== */

/* Wrapper uses inline styles + Tailwind classes from gallery widget */
/* The button inherits te-load-more-btn styles from frontend.css */

/* Dark mode disabled state */
.dark .tewido-pdf-load-more:disabled {
    background-color: rgb(75 85 99) !important;
    color: white !important;
}

/* ========================================
   RTL Support
   ======================================== */

/* Flip navigation arrow icons in RTL */
[dir="rtl"] .tewido-pdf-nav-arrow svg,
html[dir="rtl"] .tewido-pdf-nav-arrow svg {
    transform: scaleX(-1);
}

/* Swap page shadows for RTL */
[dir="rtl"] .tewido-pdf-page-left,
html[dir="rtl"] .tewido-pdf-page-left {
    border-radius: 0 4px 4px 0;
    box-shadow:
        inset 30px 0 40px -20px rgba(0, 0, 0, 0.15),
        2px 0 10px rgba(0, 0, 0, 0.2);
}

[dir="rtl"] .tewido-pdf-page-right,
html[dir="rtl"] .tewido-pdf-page-right {
    border-radius: 4px 0 0 4px;
    box-shadow:
        inset -30px 0 40px -20px rgba(0, 0, 0, 0.15),
        -2px 0 10px rgba(0, 0, 0, 0.2);
}

/* Swap page number positions in RTL */
[dir="rtl"] .tewido-pdf-page-num-left,
html[dir="rtl"] .tewido-pdf-page-num-left {
    left: auto;
    right: 16px;
}

[dir="rtl"] .tewido-pdf-page-num-right,
html[dir="rtl"] .tewido-pdf-page-num-right {
    right: auto;
    left: 16px;
}

/* RTL slide animations - reversed directions */
[dir="rtl"] .tewido-pdf-page-right.slide-out-left,
html[dir="rtl"] .tewido-pdf-page-right.slide-out-left,
[dir="rtl"] .tewido-pdf-page-left.slide-out-left,
html[dir="rtl"] .tewido-pdf-page-left.slide-out-left {
    transform: translateX(30px);
}

[dir="rtl"] .tewido-pdf-page-right.slide-out-right,
html[dir="rtl"] .tewido-pdf-page-right.slide-out-right,
[dir="rtl"] .tewido-pdf-page-left.slide-out-right,
html[dir="rtl"] .tewido-pdf-page-left.slide-out-right {
    transform: translateX(-30px);
}

/* RTL zoom margin */
[dir="rtl"] .tewido-pdf-flipbook .tewido-pdf-zoom,
html[dir="rtl"] .tewido-pdf-flipbook .tewido-pdf-zoom {
    margin-right: 0;
    margin-left: 8px;
}

/* RTL Mobile - Swap arrow positions */
@media (max-width: 768px) {
    [dir="rtl"] .tewido-pdf-nav-arrow.tewido-pdf-prev,
    html[dir="rtl"] .tewido-pdf-nav-arrow.tewido-pdf-prev {
        left: auto;
        right: 8px;
    }

    [dir="rtl"] .tewido-pdf-nav-arrow.tewido-pdf-next,
    html[dir="rtl"] .tewido-pdf-nav-arrow.tewido-pdf-next {
        right: auto;
        left: 8px;
    }
}
