/* WP Flipbook 3D - DFlip Edition */

/* Wrapper */
.flipbook-wrapper {
    max-width: 100%;
    margin: 30px auto;
    padding: 30px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Container */
.flipbook-container {
    position: relative;
    margin: 0 auto 20px;
    background: radial-gradient(ellipse at center, #3a3a3a 0%, #1a1a1a 100%);
    border-radius: 10px;
    overflow: hidden;
    box-shadow:
        inset 0 0 60px rgba(0, 0, 0, 0.6),
        0 5px 30px rgba(0, 0, 0, 0.5);
}

/* Image Zoom - will-change applied dynamically via JS for active pages only */
.stf__block {
    transition: transform 0.3s ease-out;
}

.stf__block.wpf-active-page {
    will-change: transform;
}

/* Mobile Mode Styles - Portrait single page mode */
.stf__parent.mobile-mode {
    /* Native portrait mode styling */
    width: 100% !important;
    max-width: 100%;
}

.stf__parent.mobile-mode .stf__wrapper {
    /* StPageFlip handles single page in portrait mode */
    width: 100% !important;
}

.stf__parent.mobile-mode .stf__block {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* Mobile portrait mode optimizations */
.stf__parent.mobile-mode .stf__hard-page,
.stf__parent.mobile-mode .stf__sheet {
    /* Ensure single page fills the container */
    width: 100% !important;
}

/* Ensure the flipbook container centers content */
.flipbook-container:has(.mobile-mode) {
    display: flex;
    justify-content: center;
}

/* Mobile RTL specific adjustments */
.stf__parent.mobile-mode.rtl-mode {
    direction: ltr; /* Keep LTR for flipbook structure, pages handle content direction */
}

/* Loading State */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
    z-index: 100;
}

.loading .spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 15px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Error State */
.flipbook-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: white;
    padding: 30px;
    max-width: 80%;
}

.flipbook-error .error-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.flipbook-error .error-message {
    font-size: 16px;
    line-height: 1.5;
    opacity: 0.9;
}

/* StPageFlip Container */
.stf__parent {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.stf__wrapper {
    position: relative;
}

.stf__block {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* Hover effect for page corners */
.stf__outerShadow {
    pointer-events: none;
}

.stf__hardShadow {
    pointer-events: none;
}

.stf__hardInnerShadow {
    pointer-events: none;
}

/* Page Styles */
.stf__item {
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
}

.stf__item canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Page Loading Placeholder */
.page-placeholder {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    color: #666;
}

.page-loading {
    text-align: center;
    padding: 20px;
}

.page-loading .spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 10px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.page-loaded {
    background: white;
}

/* Controls */
.flipbook-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    border-radius: 10px;
    flex-wrap: wrap;
}

/* Buttons */
.btn-prev,
.btn-next {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 20px;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 4px 20px rgba(102, 126, 234, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
    user-select: none;
}

.btn-prev .dashicons,
.btn-next .dashicons {
    width: 20px;
    height: 20px;
    font-size: 20px;
}

.btn-prev::before,
.btn-next::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.6s;
}

.btn-prev:hover,
.btn-next:hover {
    transform: translateY(-3px);
    box-shadow:
        0 6px 25px rgba(102, 126, 234, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-prev:hover::before,
.btn-next:hover::before {
    left: 100%;
}

.btn-prev:active,
.btn-next:active {
    transform: translateY(-1px);
}

.btn-prev:disabled,
.btn-next:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Page Info */
.page-info {
    font-size: 14px;
    font-weight: 600;
    color: white;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    min-width: 100px;
    text-align: center;
    user-select: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.page-info .current {
    color: #ffd700;
    font-size: 18px;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* Extra Controls */
.flipbook-extra-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-extra {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    color: white;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    user-select: none;
}

.btn-extra:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    color: white;
}

.btn-extra:active {
    transform: translateY(0);
}

.btn-extra .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

.btn-download {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.4);
}

.btn-download:hover {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.6);
}

.btn-print {
    background: rgba(33, 150, 243, 0.2);
    border-color: rgba(33, 150, 243, 0.4);
}

.btn-print:hover {
    background: rgba(33, 150, 243, 0.3);
    border-color: rgba(33, 150, 243, 0.6);
}

.btn-zoom {
    background: rgba(255, 152, 0, 0.2);
    border-color: rgba(255, 152, 0, 0.4);
}

.btn-zoom:hover {
    background: rgba(255, 152, 0, 0.3);
    border-color: rgba(255, 152, 0, 0.6);
}

/* Fullscreen mode */
.flipbook-wrapper:fullscreen {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.flipbook-wrapper:fullscreen .flipbook-container {
    max-width: 95vw;
    max-height: 85vh;
    margin: 0 auto;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .flipbook-wrapper {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    .flipbook-wrapper {
        padding: 15px;
        margin: 20px auto;
    }

    .flipbook-container {
        margin: 0 auto 15px;
    }

    .btn-prev,
    .btn-next {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .btn-prev .dashicons,
    .btn-next .dashicons {
        width: 18px;
        height: 18px;
        font-size: 18px;
    }

    .page-info {
        font-size: 13px;
        padding: 8px 14px;
        min-width: 90px;
    }

    .page-info .current {
        font-size: 16px;
    }

    .flipbook-controls {
        gap: 12px;
    }

    .btn-extra {
        width: 32px;
        height: 32px;
    }

    .btn-extra .dashicons {
        font-size: 16px;
        width: 16px;
        height: 16px;
    }

    /* Mobile mode specific - single page */
    .stf__parent.mobile-mode .stf__wrapper {
        max-width: 100%;
    }

    .stf__parent.mobile-mode .stf__block {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    }

    .flipbook-container:has(.mobile-mode) {
        display: flex;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .flipbook-wrapper {
        padding: 10px;
        margin: 15px auto;
    }

    .btn-prev,
    .btn-next {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .btn-prev .dashicons,
    .btn-next .dashicons {
        width: 16px;
        height: 16px;
        font-size: 16px;
    }

    .page-info {
        font-size: 12px;
        padding: 6px 12px;
        min-width: 80px;
    }

    .page-info .current {
        font-size: 16px;
    }

    .flipbook-controls {
        gap: 10px;
        padding: 8px;
    }

    .btn-extra {
        width: 28px;
        height: 28px;
    }

    .btn-extra .dashicons {
        font-size: 14px;
        width: 14px;
        height: 14px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn-prev,
    .btn-next {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .btn-prev .dashicons,
    .btn-next .dashicons {
        width: 22px;
        height: 22px;
        font-size: 22px;
    }

    .btn-extra {
        width: 40px;
        height: 40px;
    }

    .btn-extra .dashicons {
        font-size: 20px;
        width: 20px;
        height: 20px;
    }

    .flipbook-controls {
        padding: 12px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .page-placeholder {
        background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
        color: #999;
    }
}

/* RTL Mode Styles */
/* Horizontal flip using scaleX transform (similar to vertical-mode pattern) */
.rtl-mode .stf__block {
    transform: scaleX(-1);
}

/* Invert page CONTENT (canvas) back to readable, not the container */
/* This prevents conflicts with StPageFlip 3D transforms on .stf__item */
.rtl-mode .stf__item canvas {
    transform: scaleX(-1);
}

.rtl-mode .stf__item .page-placeholder {
    transform: scaleX(-1);
}

.rtl-mode .stf__item .page-loading {
    transform: scaleX(-1);
}

/* Vertical Mode Styles */
.flipbook-container:has(.vertical-mode) {
    display: flex;
    justify-content: center;
    align-items: center;
}

.vertical-mode {
    transform: rotate(90deg);
    transform-origin: center center;
}

.vertical-mode .stf__item {
    transform: rotate(-90deg);
}

/* Print Styles */
@media print {
    .flipbook-wrapper {
        background: none;
        box-shadow: none;
        padding: 0;
    }

    .flipbook-controls {
        display: none;
    }
}

/* DFlip Container Styles */
.df-container {
    position: relative;
    width: 100%;
    height: 600px;
    background: #2F2D2F;
    border-radius: 10px;
    overflow: hidden;
}

.df-loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.df-book-stage {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.df-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.df-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.df-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.6);
}

.df-page-counter {
    color: #fff;
    font-size: 16px;
    font-weight: 500;
}

/* DFlip Mobile Optimizations */
@media (max-width: 768px) {
    .df-container {
        height: 500px;
    }

    .df-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
}

/* DFlip RTL Support */
.df-rtl .df-book {
    direction: rtl;
}
