/* Custom styles for Good Neighbor Fence */

:root {
    --color-charcoal-950: #0d0d0d;
    --color-charcoal-900: #141414;
    --color-charcoal-800: #1c1c1c;
    --color-charcoal-700: #252525;
    --color-coral-500: #e8645a;
    --color-coral-400: #f0786e;
    --color-gold-400: #d4a853;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
}

body {
    overflow-x: hidden;
}

/* Selection color */
::selection {
    background-color: rgba(232, 100, 90, 0.3);
    color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #141414;
}
::-webkit-scrollbar-thumb {
    background: #2f2f2f;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #e8645a;
}

/* Reveal animations - progressive enhancement */
.reveal {
    opacity: 1;
    transform: none;
    transition: opacity 0.7s ease, transform 0.7s ease;
}

@media (prefers-reduced-motion: no-preference) {
    .reveal {
        opacity: 0;
        transform: translateY(30px);
    }
    .reveal.revealed {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Navbar scroll state */
.nav-scrolled {
    background: rgba(13, 13, 13, 0.95) !important;
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(47, 47, 47, 0.5);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

/* Hero parallax-like effect */
#hero img {
    will-change: transform;
}

/* Service card hover glow */
.group:hover .group-hover\:bg-coral-500\/20 {
    background-color: rgba(232, 100, 90, 0.2);
}

/* Gallery hover effect */
.group:hover .group-hover\:scale-110 {
    transform: scale(1.1);
}

/* Mobile menu transitions */
#mobileMenu {
    animation: slideDown 0.3s ease forwards;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

#mobileMenu.hidden {
    animation: slideUp 0.2s ease forwards;
}

@keyframes slideUp {
    from {
        opacity: 1;
        max-height: 500px;
    }
    to {
        opacity: 0;
        max-height: 0;
    }
}

/* Back to top button */
#backToTop.visible {
    opacity: 1 !important;
    pointer-events: all !important;
}

/* Custom select arrow */
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

/* Smooth image loading */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid #e8645a;
    outline-offset: 2px;
}

/* Remove default focus outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Ensure hero text is readable */
#hero h1,
#hero p,
#hero .text-gray-300 {
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Gold accent line animation */
@keyframes shimmer {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Testimonial card hover */
.reveal:hover {
    border-color: rgba(232, 100, 90, 0.3) !important;
    transition: border-color 0.3s ease;
}

/* Form input autofill styling */
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 30px #141414 inset !important;
    -webkit-text-fill-color: #fff !important;
}
</style>

<sm-file path="script.js">
(function () {
    'use strict';

    // --- Navbar scroll effect ---
    const navbar = document.getElementById('navbar');
    const backToTop = document.getElementById('backToTop');

    function handleScroll() {
        const scrollY = window.scrollY;

        // Navbar
        if (scrollY > 80) {
            navbar.classList.add('nav-scrolled');
        } else {
            navbar.classList.remove('nav-scrolled');
        }

        // Back to top button
        if (scrollY > 600) {
            backToTop.classList.add('visible');
        } else {
            backToTop.classList.remove('visible');
        }
    }

    window.addEventListener('scroll', handleScroll, { passive: true });
    handleScroll();

    // Back to top click
    backToTop.addEventListener('click', function () {
        window.scrollTo({ top: 0, behavior: 'smooth' });
    });

    // --- Mobile menu ---
    const mobileMenuBtn = document.getElementById('mobileMenuBtn');
    const mobileMenu = document.getElementById('mobileMenu');
    const menuIcon = document.getElementById('menuIcon');
    const closeIcon = document.getElementById('closeIcon');
    const mobileLinks = document.querySelectorAll('.mobile-link');

    mobileMenuBtn.addEventListener('click', function () {
        const isOpen = !mobileMenu.classList.contains('hidden');
        if (isOpen) {
            mobileMenu.classList.add('hidden');
            menuIcon.classList.remove('hidden');
            closeIcon.classList.add('hidden');
        } else {
            mobileMenu.classList.remove('hidden');
            menuIcon.classList.add('hidden');
            closeIcon.classList.remove('hidden');
        }
    });

    mobileLinks.forEach(function (link) {
        link.addEventListener('click', function () {
            mobileMenu.classList.add('hidden');
            menuIcon.classList.remove('hidden');
            closeIcon.classList.add('hidden');
        });
    });

    // --- Scroll reveal (progressive enhancement) ---
    const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

    if (!prefersReducedMotion && 'IntersectionObserver' in window) {
        const revealElements = document.querySelectorAll('.reveal');

        const revealObserver = new IntersectionObserver(function (entries) {
            entries.forEach(function (entry) {
                if (entry.isIntersecting) {
                    entry.target.classList.add('revealed');
                    revealObserver.unobserve(entry.target);
                }
            });
        }, {
            threshold: 0.1,
            rootMargin: '0px 0px -50px 0px'
        });

        revealElements.forEach(function (el) {
            revealObserver.observe(el);
        });
    }

    // --- Contact form ---
    const contactForm = document.getElementById('contactForm');
    const successMessage = document.getElementById('successMessage');

    contactForm.addEventListener('submit', function (e) {
        e.preventDefault();

        // Simulate form submission
        const submitBtn = contactForm.querySelector('button[type="submit"]');
        const originalText = submitBtn.innerHTML;
        submitBtn.innerHTML = '<svg class="animate-spin w-5 h-5" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="3" stroke-opacity="0.3"/><path d="M12 2a10 10 0 019.95 9" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg> Sending...';
        submitBtn.disabled = true;

        setTimeout(function () {
            contactForm.reset();
            successMessage.classList.remove('hidden');
            submitBtn.innerHTML = originalText;
            submitBtn.disabled = false;

            // Hide success message after 5 seconds
            setTimeout(function () {
                successMessage.classList.add('hidden');
            }, 5000);
        }, 1500);
    });

    // --- Smooth scroll for anchor links ---
    document.querySelectorAll('a[href^="#"]').forEach(function (anchor) {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const targetId = this.getAttribute('href');
            const targetEl = document.querySelector(targetId);
            if (targetEl) {
                targetEl.scrollIntoView({ behavior: 'smooth' });
            }
        });
    });
})();
