/**
 * DearFlip Tabloid Flipbook Styles
 * CSS otimizado para flipbooks responsivos com DearFlip
 */

/* Container principal do flipbook */
.tabloid-flipbook-container {
    position: relative;
    width: 100%;
    background: #f8fafc;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    min-height: 400px;
}

/* Estado de carregamento */
.flipbook-loading {
    position: relative;
    min-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.flipbook-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 25% 25%, rgba(255,255,255,0.1) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(255,255,255,0.05) 0%, transparent 50%);
}

.flipbook-loading .loading-content {
    text-align: center;
    z-index: 1;
}

.flipbook-loading .loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.flipbook-loading h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    opacity: 0.95;
}

.flipbook-loading p {
    font-size: 0.875rem;
    opacity: 0.8;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Estado pronto */
.flipbook-ready {
    background: transparent;
}

/* Personalização dos controles DearFlip */
.df-container {
    border-radius: 8px;
    overflow: hidden;
}

.df-ui {
    border-radius: 0 0 8px 8px;
}

.df-ui-btn {
    transition: all 0.2s ease;
}

.df-ui-btn:hover {
    background-color: var(--color-primary, #fdc300) !important;
    color: white !important;
}

/* Controles customizados */
.flipbook-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    z-index: 1000;
}

.flipbook-control-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 0.5rem;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.flipbook-control-btn:hover {
    background: var(--color-primary, #fdc300);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Estado de erro */
.flipbook-error-state {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
}

.flipbook-error {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.flipbook-error .error-icon {
    color: #ef4444;
    margin-bottom: 1rem;
}

.flipbook-error h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.5rem;
}

.flipbook-error p {
    color: #6b7280;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.flipbook-error .error-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Botões de ação */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.btn-primary {
    background: var(--color-primary, #fdc300);
    color: #1f2937;
}

.btn-primary:hover {
    background: #eab308;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

/* Header do flipbook */
.flipbook-header {
    background: white;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: between;
    gap: 1rem;
}

.flipbook-info {
    flex: 1;
}

.flipbook-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.flipbook-meta {
    font-size: 0.875rem;
    color: #6b7280;
}

.flipbook-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Badge de status */
.flipbook-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.flipbook-badge.active {
    background: #dcfce7;
    color: #166534;
}

.flipbook-badge.loading {
    background: #dbeafe;
    color: #1d4ed8;
}

/* Responsividade */
@media (max-width: 768px) {
    .flipbook-header {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .flipbook-actions {
        justify-content: center;
    }

    .flipbook-controls {
        top: 0.5rem;
        right: 0.5rem;
        gap: 0.25rem;
    }

    .flipbook-control-btn {
        padding: 0.375rem;
    }

    .flipbook-error {
        padding: 1.5rem;
    }

    .flipbook-error .error-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        justify-content: center;
    }

    /* Ajustar DearFlip para mobile */
    .df-container {
        margin: 0 !important;
    }

    .df-ui {
        padding: 0.5rem !important;
    }
}

@media (max-width: 640px) {
    .tabloid-flipbook-container {
        border-radius: 8px;
        margin: 0 -1rem;
    }

    .flipbook-loading {
        min-height: 400px;
    }

    .flipbook-loading h3 {
        font-size: 1.125rem;
    }
}

/* Tela cheia */
.df-container.df-fullscreen {
    background: #1f2937 !important;
}

.df-container.df-fullscreen .df-ui {
    background: rgba(0, 0, 0, 0.8) !important;
}

/* Animações de entrada */
.flipbook-ready {
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Melhorar contraste em temas escuros */
@media (prefers-color-scheme: dark) {
    .tabloid-flipbook-container {
        background: #1f2937;
    }

    .flipbook-header {
        background: #374151;
        border-color: #4b5563;
    }

    .flipbook-title {
        color: #f9fafb;
    }

    .flipbook-meta {
        color: #d1d5db;
    }

    .flipbook-error-state {
        background: #374151;
    }

    .flipbook-error h3 {
        color: #f9fafb;
    }

    .flipbook-error p {
        color: #d1d5db;
    }
}

/* Indicador de progresso personalizado */
.flipbook-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.1);
    z-index: 1001;
}

.flipbook-progress-bar {
    height: 100%;
    background: var(--color-primary, #fdc300);
    width: 0%;
    transition: width 0.3s ease;
}

/* Tooltip personalizado */
.flipbook-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    white-space: nowrap;
    z-index: 1002;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.flipbook-tooltip.visible {
    opacity: 1;
}

/* Estilos para fallback viewer */
.fallback-flipbook {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.fallback-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.fallback-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.fallback-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.fallback-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fallback-btn:hover:not(:disabled) {
    background: var(--color-primary, #fdc300);
    border-color: var(--color-primary, #fdc300);
    color: #1f2937;
}

.fallback-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.875rem;
    color: #6b7280;
    white-space: nowrap;
}

.fallback-canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 500px;
    padding: 1rem;
    background: #f8fafc;
    overflow: hidden;
    perspective: 1000px;
    width: 100%;
}

/* Garantir que o container desktop use toda a largura */
@media (min-width: 768px) {
    .fallback-canvas-container {
        min-height: 600px;
        padding: 2rem;
    }
}

/* Container para animação de flip */
.page-flipper {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease-in-out;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Modo responsivo: mostrar/esconder baseado no dispositivo */
.desktop-only {
    display: block !important;
}

.mobile-only {
    display: none !important;
}

@media (max-width: 767px) {
    .desktop-only {
        display: none !important;
        visibility: hidden;
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .mobile-only {
        display: block !important;
        visibility: visible;
        position: relative;
        top: auto;
        left: auto;
    }

    /* Mobile: page-flipper vertical */
    .page-flipper {
        flex-direction: column;
        align-items: center;
    }
}

@media (min-width: 768px) {
    .desktop-only {
        display: block !important;
        visibility: visible;
    }

    .mobile-only {
        display: none !important;
        visibility: hidden;
    }

    /* Desktop: page-flipper horizontal */
    .page-flipper {
        flex-direction: row !important;
        align-items: flex-start !important;
        justify-content: center !important;
        width: 100% !important;
    }

    .page-spread {
        width: 100% !important;
        max-width: 1200px !important;
    }
}

/* Garantir que canvas desktop não apareçam no mobile */
@media (max-width: 767px) {
    .page-spread,
    .page-left,
    .page-right,
    #canvasLeft-*,
    #canvasRight-* {
        display: none !important;
        visibility: hidden;
        width: 0;
        height: 0;
        opacity: 0;
    }
}

/* Folha dupla (Desktop) - Layout horizontal */
.page-spread {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-gap: 30px !important;
    perspective: 1200px;
    width: 100% !important;
    min-height: 500px;
    box-sizing: border-box;
}

.page-left,
.page-right {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 200px !important;
    transform-style: preserve-3d;
    display: block !important;
}

.page-left {
    grid-column: 1;
}

.page-right {
    grid-column: 2;
}

.page-left canvas,
.page-right canvas {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    transition: transform 0.3s ease;
    display: block !important;
    margin: 0 auto;
}

/* Efeitos específicos da folha esquerda e direita */
.page-left {
    transform-origin: right center;
}

.page-right {
    transform-origin: left center;
}

/* Folha única (Mobile) */
.page-current,
.page-next {
    position: relative;
}

.page-next {
    position: absolute;
    top: 0;
    left: 0;
    transform: rotateY(-180deg);
}

.page-current canvas,
.page-next canvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    transition: transform 0.3s ease;
}

/* Animações de flip para mobile (página única) */
.page-flipper.flipping-next {
    animation: flipToNext 0.6s ease-in-out;
}

.page-flipper.flipping-prev {
    animation: flipToPrev 0.6s ease-in-out;
}

@keyframes flipToNext {
    0% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(-90deg) scale(0.8);
    }
    100% {
        transform: rotateY(-180deg);
    }
}

@keyframes flipToPrev {
    0% {
        transform: rotateY(-180deg);
    }
    50% {
        transform: rotateY(-90deg) scale(0.8);
    }
    100% {
        transform: rotateY(0deg);
    }
}

/* Animações de flip para desktop (folha dupla) */
.page-flipper.flipping-next-double {
    animation: flipDoubleNext 0.6s ease-in-out;
}

.page-flipper.flipping-prev-double {
    animation: flipDoublePrev 0.6s ease-in-out;
}

@keyframes flipDoubleNext {
    0% {
        transform: perspective(1200px) rotateY(0deg);
    }
    25% {
        transform: perspective(1200px) rotateY(-15deg) scale(0.95);
    }
    50% {
        transform: perspective(1200px) rotateY(-45deg) scale(0.9);
    }
    75% {
        transform: perspective(1200px) rotateY(-15deg) scale(0.95);
    }
    100% {
        transform: perspective(1200px) rotateY(0deg);
    }
}

@keyframes flipDoublePrev {
    0% {
        transform: perspective(1200px) rotateY(0deg);
    }
    25% {
        transform: perspective(1200px) rotateY(15deg) scale(0.95);
    }
    50% {
        transform: perspective(1200px) rotateY(45deg) scale(0.9);
    }
    75% {
        transform: perspective(1200px) rotateY(15deg) scale(0.95);
    }
    100% {
        transform: perspective(1200px) rotateY(0deg);
    }
}

/* Efeitos individuais das páginas durante a animação dupla */
.page-flipper.flipping-next-double .page-right {
    animation: pageFlipNext 0.6s ease-in-out;
}

.page-flipper.flipping-prev-double .page-left {
    animation: pageFlipPrev 0.6s ease-in-out;
}

@keyframes pageFlipNext {
    0% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(-90deg);
    }
    100% {
        transform: rotateY(-180deg);
    }
}

@keyframes pageFlipPrev {
    0% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(90deg);
    }
    100% {
        transform: rotateY(180deg);
    }
}

/* Efeito de hover nas páginas */
.page-current canvas:hover {
    transform: scale(1.02);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

/* Efeitos hover para folha dupla */
.page-left canvas:hover {
    transform: scale(1.02) rotateY(5deg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.page-right canvas:hover {
    transform: scale(1.02) rotateY(-5deg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

/* Separador visual entre páginas duplas */
.page-spread::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 10%;
    bottom: 10%;
    width: 2px;
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1), transparent);
    transform: translateX(-50%);
    z-index: 1;
}

/* Efeito de loading na transição */
.page-flipper.flipping-next .page-current,
.page-flipper.flipping-prev .page-current {
    opacity: 0.7;
}

/* Indicador visual de que pode virar página */
.page-flipper::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.page-flipper:hover::before {
    opacity: 1;
}

/* Sombra dinâmica durante a animação */
.page-flipper.flipping-next::after,
.page-flipper.flipping-prev::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 20px;
    background: radial-gradient(ellipse, rgba(0, 0, 0, 0.3), transparent);
    animation: shadowPulse 0.6s ease-in-out;
}

@keyframes shadowPulse {
    0%, 100% {
        opacity: 0.3;
        transform: translateX(-50%) scale(1);
    }
    50% {
        opacity: 0.6;
        transform: translateX(-50%) scale(1.2);
    }
}

.fallback-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6b7280;
}

.fallback-loading .loading-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid var(--color-primary, #fdc300);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 0.5rem;
}

/* Basic viewer styles */
.basic-viewer {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.basic-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.basic-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
}

/* Responsividade para fallback */
@media (max-width: 768px) {
    .fallback-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .fallback-controls {
        justify-content: center;
        flex-wrap: wrap;
    }

    .fallback-actions {
        justify-content: center;
    }

    .fallback-btn {
        padding: 0.625rem 1rem;
    }

    .fallback-canvas-container {
        padding: 0.5rem;
        min-height: 400px;
        perspective: 800px;
    }

    .basic-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        gap: 0.75rem;
    }

    /* Animações simplificadas para mobile */
    @keyframes flipToNext {
        0% {
            transform: translateX(0) scale(1);
        }
        50% {
            transform: translateX(-50px) scale(0.9) rotateY(-45deg);
        }
        100% {
            transform: translateX(-100px) scale(1);
        }
    }

    @keyframes flipToPrev {
        0% {
            transform: translateX(-100px) scale(1);
        }
        50% {
            transform: translateX(-50px) scale(0.9) rotateY(45deg);
        }
        100% {
            transform: translateX(0) scale(1);
        }
    }

    /* Indicadores de swipe para mobile */
    .page-flipper::before {
        width: 30px;
        background: linear-gradient(90deg, transparent, rgba(253, 195, 0, 0.2));
    }

    .page-flipper::after {
        content: '👆 Deslize para virar';
        position: absolute;
        bottom: -40px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 0.75rem;
        color: #6b7280;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
        white-space: nowrap;
    }

    .page-flipper:hover::after {
        opacity: 1;
    }
}

/* Touch feedback */
.page-flipper.touching {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

/* Feedback visual de swipe */
.page-flipper.swiping-next {
    transform: translateX(-10px) scale(0.95);
}

.page-flipper.swiping-prev {
    transform: translateX(10px) scale(0.95);
}

.page-flipper.swiping-next::before {
    background: linear-gradient(90deg, transparent, rgba(34, 197, 94, 0.3));
    opacity: 1;
}

.page-flipper.swiping-prev::before {
    background: linear-gradient(270deg, transparent, rgba(34, 197, 94, 0.3));
    opacity: 1;
    left: 0;
    right: auto;
}

/* Preload indicator para próxima página */
.page-flipper.loading-next::before {
    background: linear-gradient(90deg, transparent, rgba(253, 195, 0, 0.4));
    animation: shimmer 1s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* Estados de loading melhorados */
.flipbook-loading .loading-content {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}