/**
 * Back to Top Button Styles - Optimized for performance
 */

.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000; /* Increased to be above blog reading progress bar */
    opacity: 0; /* Hidden by default */
    visibility: hidden; /* Hidden by default */
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateY(20px); /* Start position for animation */
    /* Hardware acceleration for smoother animations */
    will-change: transform, opacity;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Prevent text selection */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background-color: #1a2028; /* Hardcoded dark background */
    color: #D4A968; /* Hardcoded gold color */
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(212, 169, 104, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
    position: relative;
    overflow: hidden;
    text-decoration: none;
    /* Hardware acceleration */
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Improve touch response */
    touch-action: manipulation;
    cursor: pointer;
}

.back-to-top-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(212, 169, 104, 0.1) 0%, rgba(212, 169, 104, 0) 70%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.back-to-top-btn:hover,
.back-to-top-btn:focus,
.back-to-top-btn.active {
    transform: translateY(-5px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
    background-color: rgba(26, 32, 40, 0.95);
    border-color: #D4A968; /* Hardcoded gold color */
    outline: none; /* Remove outline for better aesthetics */
}

.back-to-top-btn:hover:before,
.back-to-top-btn:focus:before,
.back-to-top-btn.active:before {
    opacity: 1;
}

.back-to-top-btn i {
    font-size: 1.2rem;
    /* Optimize animation for performance */
    animation: float 2s ease-in-out infinite;
    will-change: transform;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* Tactical pulse effect - fixed and optimized */
.back-to-top-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(212, 169, 104, 0.1) 0%, rgba(212, 169, 104, 0) 70%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Pulse animation removed as requested */

/* Reduce animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .back-to-top {
        transition: opacity 0.1s ease, visibility 0.1s ease;
        transform: none;
    }

    .back-to-top.visible {
        transform: none;
    }

    .back-to-top-btn {
        transition: background-color 0.1s ease, border-color 0.1s ease;
    }

    .back-to-top-btn:hover,
    .back-to-top-btn:focus,
    .back-to-top-btn.active {
        transform: none;
    }

    .back-to-top-btn i {
        animation: none;
    }
}

/* Ensure proper positioning on blog pages but allow scroll behavior */
.blog-main ~ .back-to-top,
body.home .back-to-top,
body.blog .back-to-top,
body.category .back-to-top,
body.tag .back-to-top {
    z-index: 99999 !important;
    position: fixed !important;
    bottom: 30px !important;
    right: 30px !important;
}

/* Ensure button styling is preserved on blog pages */
.blog-main ~ .back-to-top .back-to-top-btn,
body.home .back-to-top .back-to-top-btn,
body.blog .back-to-top .back-to-top-btn,
body.category .back-to-top .back-to-top-btn,
body.tag .back-to-top .back-to-top-btn {
    width: 50px !important;
    height: 50px !important;
    background-color: #1a2028 !important; /* Hardcoded dark background */
    color: #D4A968 !important; /* Hardcoded gold color */
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
    border: 1px solid rgba(212, 169, 104, 0.3) !important;
    text-decoration: none !important;
    cursor: pointer !important;
}

/* Mobile adjustments - Aligned with WhatsApp widget
 * Desktop positioning remains unchanged (bottom: 30px, right: 30px)
 * Mobile: Both widgets aligned at same vertical level with proper horizontal spacing
 * WhatsApp widget: left side, Back to top: right side
 */
@media (max-width: 768px) {
    .back-to-top {
        bottom: calc(var(--spacing-md) + 60px); /* Match WhatsApp widget vertical position */
        right: var(--spacing-md); /* Match WhatsApp widget horizontal spacing */
        left: auto; /* Ensure it stays on the right */
    }

    /* Force visibility on blog pages - mobile */
    .blog-main ~ .back-to-top,
    body.home .back-to-top,
    body.blog .back-to-top,
    body.category .back-to-top,
    body.tag .back-to-top {
        bottom: calc(var(--spacing-md) + 60px) !important; /* Match WhatsApp widget vertical position */
        right: var(--spacing-md) !important; /* Match WhatsApp widget horizontal spacing */
        left: auto !important; /* Ensure it stays on the right */
    }

    .back-to-top-btn {
        width: 48px; /* Slightly larger for better touch target */
        height: 48px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); /* Stronger shadow for better visibility */
    }

    /* Larger touch target for mobile - using a different approach to avoid conflicts */
    .back-to-top-btn {
        position: relative;
    }

    /* Ensure proper spacing from WhatsApp widget on very small screens */
    @media (max-width: 480px) {
        .back-to-top {
            bottom: calc(var(--spacing-sm) + 50px) !important; /* Slightly lower on very small screens */
        }

        .blog-main ~ .back-to-top,
        body.home .back-to-top,
        body.blog .back-to-top,
        body.category .back-to-top,
        body.tag .back-to-top {
            bottom: calc(var(--spacing-sm) + 50px) !important;
        }
    }

    /* Pulse effect removed as requested */

    /* Active state for touch devices */
    .back-to-top-btn.active {
        transform: scale(0.95) !important; /* Override any other transform */
        background-color: rgba(26, 32, 40, 0.95);
        border-color: #D4A968; /* Hardcoded gold color */
        transition: transform 0.1s ease, background-color 0.1s ease, border-color 0.1s ease;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); /* Pressed effect */
    }
}

/* Emergency fallback removed - now using scroll-based visibility */
