<?php
session_start();

require_once "config/database.php";

/* =========================
   GET FEATURED PRODUCTS
   ========================= */

$featured_products = [];

$sql = "SELECT id, name, category, price, description, image, stock
        FROM products
        ORDER BY id DESC
        LIMIT 8";

$result = $conn->query($sql);

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $featured_products[] = $row;
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">

    <title>Muthu Jewellers | Elegance That Lasts Forever</title>

    <style>

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: Arial, sans-serif;
        }

        body {
            background: #fffaf5;
            color: #222;
        }


        /* ==================================================
           NAVIGATION
           ================================================== */

        nav {
            background: #111;
            color: white;

            padding: 18px 7%;

            display: flex;
            justify-content: space-between;
            align-items: center;

            position: sticky;
            top: 0;
            z-index: 1000;

            box-shadow: 0 3px 12px rgba(0,0,0,0.2);
        }

       .logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.logo img {
    width: 190px;
    height: 55px;
    object-fit: contain;
    display: block;
}

        nav ul {
            list-style: none;

            display: flex;
            align-items: center;

            gap: 28px;
        }

        nav ul li a {
            color: white;
            text-decoration: none;

            font-size: 16px;

            transition: 0.3s;
        }

        nav ul li a:hover {
            color: #d4af37;
        }


        /* ==================================================
           HERO
           ================================================== */

        .hero {

            min-height: 570px;

            padding: 60px 7%;

            display: flex;
            align-items: center;

            background:
                radial-gradient(
                    circle at 80% 30%,
                    rgba(212,175,55,0.22),
                    transparent 28%
                ),
                linear-gradient(
                    135deg,
                    #171717,
                    #353535
                );

            color: white;
        }

        .hero-container {

            width: 100%;
            max-width: 1200px;

            margin: auto;

            display: grid;
            grid-template-columns: 1.1fr 0.9fr;

            gap: 50px;

            align-items: center;
        }

        .hero-content {
            max-width: 650px;
        }

        .small-title {

            color: #d4af37;

            letter-spacing: 5px;

            font-size: 14px;

            font-weight: bold;

            margin-bottom: 18px;
        }

        .hero-content h1 {

            font-size: 58px;

            line-height: 1.1;

            margin-bottom: 18px;
        }

        .hero-content h1 span {
            color: #d4af37;
        }

        .hero-content h2 {

            font-size: 28px;

            margin-bottom: 20px;

            font-weight: normal;
        }

        .hero-content p {

            color: #ddd;

            font-size: 17px;

            line-height: 1.8;

            margin-bottom: 30px;
        }

        .hero-buttons {

            display: flex;
            gap: 15px;

            flex-wrap: wrap;
        }

        .shop-btn {

            display: inline-block;

            background: #d4af37;

            color: #111;

            padding: 15px 32px;

            border-radius: 6px;

            text-decoration: none;

            font-weight: bold;

            transition: 0.3s;
        }

        .shop-btn:hover {
            background: white;
            transform: translateY(-3px);
        }

        .contact-btn {

            display: inline-block;

            border: 1px solid #d4af37;

            color: #d4af37;

            padding: 14px 30px;

            border-radius: 6px;

            text-decoration: none;

            font-weight: bold;

            transition: 0.3s;
        }

        .contact-btn:hover {
            background: #d4af37;
            color: #111;
        }


        /* ==================================================
           HERO JEWELLERY DISPLAY
           ================================================== */

        .hero-jewel {

            min-height: 390px;

            display: flex;

            align-items: center;

            justify-content: center;

            position: relative;
        }

        .jewel-circle {

            width: 330px;
            height: 330px;

            border-radius: 50%;

            background:
                radial-gradient(
                    circle,
                    #fff8df 0%,
                    #e8d39a 35%,
                    #b08b20 70%,
                    #6f5310 100%
                );

            display: flex;

            align-items: center;
            justify-content: center;

            box-shadow:
                0 0 70px rgba(212,175,55,0.25);

            border: 8px solid rgba(212,175,55,0.3);
        }

        .jewel-icon {

            font-size: 150px;

            filter:
                drop-shadow(
                    0 10px 15px
                    rgba(0,0,0,0.35)
                );
        }

        .floating-card {

            position: absolute;

            background: white;

            color: #222;

            padding: 15px 20px;

            border-radius: 10px;

            box-shadow:
                0 8px 25px
                rgba(0,0,0,0.25);

            font-weight: bold;
        }

        .floating-card.top {
            top: 30px;
            right: 20px;
        }

        .floating-card.bottom {
            bottom: 30px;
            left: 20px;
        }

        .floating-card span {
            color: #b08b20;
        }


        /* ==================================================
           CATEGORY SECTION
           ================================================== */

        .categories {

            padding: 70px 7%;

            text-align: center;
        }

        .section-label {

            color: #b08b20;

            letter-spacing: 3px;

            font-size: 13px;

            font-weight: bold;

            margin-bottom: 10px;
        }

        .section-title {

            font-size: 38px;

            margin-bottom: 12px;
        }

        .section-description {

            color: #666;

            max-width: 650px;

            margin: 0 auto 45px;

            line-height: 1.7;
        }

        .category-container {

            max-width: 1200px;

            margin: auto;

            display: grid;

            grid-template-columns:
                repeat(4, 1fr);

            gap: 20px;
        }

        .category-card {

            background: white;

            padding: 28px 20px;

            border-radius: 12px;

            box-shadow:
                0 5px 20px
                rgba(0,0,0,0.08);

            transition: 0.3s;

            text-decoration: none;

            color: #222;
        }

        .category-card:hover {

            transform: translateY(-8px);

            box-shadow:
                0 12px 28px
                rgba(0,0,0,0.15);
        }

        .category-icon {

            width: 80px;
            height: 80px;

            margin: 0 auto 18px;

            border-radius: 50%;

            background: #fff7df;

            display: flex;

            align-items: center;
            justify-content: center;

            font-size: 42px;
        }

        .category-card h3 {

            color: #b08b20;

            font-size: 20px;

            margin-bottom: 8px;
        }

        .category-card p {

            color: #777;

            font-size: 14px;

            line-height: 1.5;
        }


        /* ==================================================
           FEATURED PRODUCTS
           ================================================== */

        .products-section {

            padding: 70px 7%;

            background: #f8f3ed;
        }

        .products-header {

            max-width: 1200px;

            margin: auto;

            display: flex;

            justify-content: space-between;

            align-items: end;

            margin-bottom: 35px;
        }

        .products-header h2 {

            font-size: 36px;
        }

        .view-all {

            color: #b08b20;

            text-decoration: none;

            font-weight: bold;
        }

        .product-grid {

            max-width: 1200px;

            margin: auto;

            display: grid;

            grid-template-columns:
                repeat(4, 1fr);

            gap: 22px;
        }

        .product-card {

            background: white;

            border-radius: 12px;

            overflow: hidden;

            box-shadow:
                0 5px 18px
                rgba(0,0,0,0.08);

            transition: 0.3s;

            position: relative;
        }

        .product-card:hover {

            transform: translateY(-6px);

            box-shadow:
                0 12px 25px
                rgba(0,0,0,0.15);
        }

        .product-image {

            height: 230px;

            background: #f5f5f5;

            display: flex;

            align-items: center;
            justify-content: center;

            overflow: hidden;
        }

        .product-image img {

            width: 100%;
            height: 100%;

            object-fit: cover;

            transition: 0.4s;
        }

        .product-card:hover .product-image img {
            transform: scale(1.05);
        }

        .no-image {

            font-size: 65px;

            color: #d4af37;
        }

        .product-info {

            padding: 18px;
        }

        .product-category {

            color: #b08b20;

            font-size: 12px;

            text-transform: uppercase;

            letter-spacing: 1px;

            margin-bottom: 7px;
        }

        .product-info h3 {

            font-size: 18px;

            margin-bottom: 8px;
        }

        .product-description {

            color: #777;

            font-size: 13px;

            line-height: 1.5;

            min-height: 40px;

            margin-bottom: 12px;
        }

        .product-bottom {

            display: flex;

            justify-content: space-between;

            align-items: center;
        }

        .price {

            color: #b08b20;

            font-size: 18px;

            font-weight: bold;
        }

        .cart-btn {

            background: #d4af37;

            color: #111;

            text-decoration: none;

            padding: 9px 13px;

            border-radius: 5px;

            font-size: 13px;

            font-weight: bold;
        }

        .cart-btn:hover {
            background: #111;
            color: #d4af37;
        }


        /* ==================================================
           WHY CHOOSE US
           ================================================== */

        .why-section {

            padding: 70px 7%;

            text-align: center;

            background: white;
        }

        .why-container {

            max-width: 1100px;

            margin: 40px auto 0;

            display: grid;

            grid-template-columns:
                repeat(3, 1fr);

            gap: 25px;
        }

        .why-card {

            padding: 30px;

            border: 1px solid #eee;

            border-radius: 12px;
        }

        .why-icon {

            font-size: 42px;

            margin-bottom: 15px;
        }

        .why-card h3 {

            margin-bottom: 10px;

            color: #b08b20;
        }

        .why-card p {

            color: #666;

            line-height: 1.6;

            font-size: 14px;
        }


        /* ==================================================
           CTA
           ================================================== */

        .cta {

            margin: 0;

            padding: 70px 7%;

            text-align: center;

            background:
                linear-gradient(
                    rgba(0,0,0,0.78),
                    rgba(0,0,0,0.78)
                ),
                #333;

            color: white;
        }

        .cta h2 {

            font-size: 38px;

            margin-bottom: 15px;
        }

        .cta p {

            color: #ddd;

            margin-bottom: 28px;

            font-size: 17px;
        }


        /* ==================================================
           FOOTER
           ================================================== */

        footer {

            background: #111;

            color: white;

            padding: 35px 7% 20px;

            text-align: center;
        }

        footer h3 {

            color: #d4af37;

            font-size: 25px;

            margin-bottom: 10px;
        }

        footer p {

            color: #aaa;

            font-size: 14px;

            margin-bottom: 8px;
        }

        footer span {
            color: #d4af37;
        }


        /* ==================================================
           RESPONSIVE
           ================================================== */

        @media (max-width: 1000px) {

            .hero-container {
                grid-template-columns: 1fr;
                text-align: center;
            }

            .hero-content {
                margin: auto;
            }

            .hero-buttons {
                justify-content: center;
            }

            .category-container {
                grid-template-columns:
                    repeat(3, 1fr);
            }

            .product-grid {
                grid-template-columns:
                    repeat(3, 1fr);
            }

        }


        @media (max-width: 750px) {

            nav {
                flex-direction: column;
                gap: 15px;
            }

            nav ul {
                gap: 15px;
                flex-wrap: wrap;
                justify-content: center;
            }

            .hero-content h1 {
                font-size: 42px;
            }

            .hero-content h2 {
                font-size: 23px;
            }

            .jewel-circle {
                width: 260px;
                height: 260px;
            }

            .jewel-icon {
                font-size: 110px;
            }

            .category-container {
                grid-template-columns:
                    repeat(2, 1fr);
            }

            .product-grid {
                grid-template-columns:
                    repeat(2, 1fr);
            }

            .why-container {
                grid-template-columns: 1fr;
            }

            .products-header {
                align-items: start;
                flex-direction: column;
                gap: 10px;
            }

        }


        @media (max-width: 500px) {

            .logo img {
    width: 230px;
    height: 65px;
    object-fit: contain;
    display: block;
}

            nav ul {
                gap: 12px;
            }

            nav ul li a {
                font-size: 14px;
            }

            .hero {
                padding: 50px 20px;
            }

            .hero-content h1 {
                font-size: 36px;
            }

            .hero-content p {
                font-size: 15px;
            }

            .category-container {
                grid-template-columns: 1fr;
            }

            .product-grid {
                grid-template-columns: 1fr;
            }

            .section-title {
                font-size: 30px;
            }

            .cta h2 {
                font-size: 30px;
            }

        }

    </style>

</head>


<body>


<!-- ==================================================
     NAVIGATION
     ================================================== -->

<nav>

    <a href="index.php" class="logo">
    <img src="images/logo.png" alt="Muthu Jewellers Logo">
</a>

    <ul>

        <li>
            <a href="index.php">Home</a>
        </li>

        <li>
            <a href="shop.php">Shop</a>
        </li>

        <li>
            <a href="cart.php">Cart 🛒</a>
        </li>

        <li>
            <a href="checkout.php">Checkout</a>
        </li>

        <li>
    <a href="track-order.php">My Orders 📦</a>
</li>

        <li>
            <a href="delivery.php">Delivery</a>
        </li>

        <li>
            <a href="contact.php">Contact</a>
        </li>

    </ul>

</nav>


<!-- ==================================================
     HERO SECTION
     ================================================== -->

<section class="hero">

    <div class="hero-container">


        <div class="hero-content">

            <div class="small-title">
                WELCOME TO MUTHU JEWELLERS
            </div>

            <h1>
                Jewellery That
                <span>Shines</span>
                With You
            </h1>

            <h2>
                Elegance That Lasts Forever ✨
            </h2>

            <p>
                Discover our beautiful jewellery collections
                created to make every special moment unforgettable.
                Find elegant pieces for yourself or someone special.
            </p>

            <div class="hero-buttons">

                <a href="shop.php"
                   class="shop-btn">
                    Shop Now 💎
                </a>

                <a href="contact.php"
                   class="contact-btn">
                    Contact Us 💬
                </a>

            </div>

        </div>


        <div class="hero-jewel">

            <div class="jewel-circle">

                <div class="jewel-icon">
                    💎
                </div>

            </div>

            <div class="floating-card top">
                ✨ <span>Premium</span> Collection
            </div>

            <div class="floating-card bottom">
                💍 Beautiful Jewellery
            </div>

        </div>


    </div>

</section>


<!-- ==================================================
     CATEGORIES
     ================================================== -->

<section class="categories">

    <div class="section-label">
        EXPLORE
    </div>

    <h2 class="section-title">
        Shop By Category
    </h2>

    <p class="section-description">
        Explore our carefully selected jewellery collections
        and find the perfect piece for every occasion.
    </p>


    <div class="category-container">


        <a href="shop.php?category=Rings"
           class="category-card">

            <div class="category-icon">
                💍
            </div>

            <h3>Rings</h3>

            <p>
                Elegant rings for every special moment.
            </p>

        </a>


        <a href="shop.php?category=Necklaces"
           class="category-card">

            <div class="category-icon">
                📿
            </div>

            <h3>Necklaces</h3>

            <p>
                Beautiful necklaces to complete your look.
            </p>

        </a>


        <a href="shop.php?category=Earrings"
           class="category-card">

            <div class="category-icon">
                ✨
            </div>

            <h3>Earrings</h3>

            <p>
                Stylish earrings for every occasion.
            </p>

        </a>


        <a href="shop.php?category=Bracelets"
           class="category-card">

            <div class="category-icon">
                💫
            </div>

            <h3>Bracelets</h3>

            <p>
                Add elegance with beautiful bracelets.
            </p>

        </a>


        <a href="shop.php?category=Pendants"
           class="category-card">

            <div class="category-icon">
                💎
            </div>

            <h3>Pendants</h3>

            <p>
                Delicate pendants with timeless beauty.
            </p>

        </a>


        <a href="shop.php?category=Hair Clips"
           class="category-card">

            <div class="category-icon">
                🎀
            </div>

            <h3>Hair Clips</h3>

            <p>
                Beautiful accessories for your hairstyle.
            </p>

        </a>


        <a href="shop.php?category=Anklets"
           class="category-card">

            <div class="category-icon">
                ✨
            </div>

            <h3>Anklets</h3>

            <p>
                Stylish anklets for an elegant touch.
            </p>

        </a>


        <a href="shop.php?category=Brooches"
           class="category-card">

            <div class="category-icon">
                🌸
            </div>

            <h3>Brooches</h3>

            <p>
                Unique brooches to complete your outfit.
            </p>

        </a>


    </div>

</section>


<!-- ==================================================
     FEATURED PRODUCTS
     ================================================== -->

<section class="products-section">

    <div class="products-header">

        <div>

            <div class="section-label">
                OUR COLLECTION
            </div>

            <h2>
                Featured Products 💎
            </h2>

        </div>

        <a href="shop.php"
           class="view-all">
            View All Products →
        </a>

    </div>


    <div class="product-grid">


        <?php if (!empty($featured_products)): ?>


            <?php foreach ($featured_products as $product): ?>


                <div class="product-card">


                    <div class="product-image">

                        <?php

                        /*
                         * Product image path
                         * Change only if your upload folder
                         * is different.
                         */

                        $image_path = "assets/images/" . $product["image"];

                        ?>

                        <?php if (
                            !empty($product["image"]) &&
                            file_exists($image_path)
                        ): ?>

                            <img
                                src="<?php echo htmlspecialchars($image_path); ?>"
                                alt="<?php echo htmlspecialchars($product["name"]); ?>"
                            >

                        <?php else: ?>

                            <div class="no-image">
                                💎
                            </div>

                        <?php endif; ?>

                    </div>


                    <div class="product-info">


                        <div class="product-category">

                            <?php
                            echo htmlspecialchars(
                                $product["category"]
                            );
                            ?>

                        </div>


                        <h3>

                            <?php
                            echo htmlspecialchars(
                                $product["name"]
                            );
                            ?>

                        </h3>


                        <p class="product-description">

                            <?php

                            $description =
                                $product["description"];

                            if (
                                strlen($description) > 75
                            ) {
                                $description =
                                    substr(
                                        $description,
                                        0,
                                        75
                                    ) . "...";
                            }

                            echo htmlspecialchars(
                                $description
                            );

                            ?>

                        </p>


                        <div class="product-bottom">

                            <div class="price">

                                Rs.
                                <?php
                                echo number_format(
                                    $product["price"],
                                    2
                                );
                                ?>

                            </div>


                            <a
                                href="product.php?id=<?php echo $product['id']; ?>"
                                class="cart-btn"
                            >
                                View Product
                            </a>

                        </div>


                    </div>


                </div>


            <?php endforeach; ?>


        <?php else: ?>


            <div
                style="
                    grid-column:1/-1;
                    text-align:center;
                    padding:50px;
                    color:#777;
                "
            >

                <div style="font-size:60px;">
                    💎
                </div>

                <h3>
                    Products Coming Soon
                </h3>

                <p>
                    Our beautiful jewellery collection
                    will appear here.
                </p>

            </div>


        <?php endif; ?>


    </div>

</section>


<!-- ==================================================
     WHY CHOOSE US
     ================================================== -->

<section class="why-section">

    <div class="section-label">
        WHY MUTHU JEWELLERS
    </div>

    <h2 class="section-title">
        Jewellery Made For You
    </h2>

    <div class="why-container">


        <div class="why-card">

            <div class="why-icon">
                💎
            </div>

            <h3>
                Beautiful Designs
            </h3>

            <p>
                Discover carefully selected jewellery
                designs made to match your style.
            </p>

        </div>


        <div class="why-card">

            <div class="why-icon">
                🛍️
            </div>

            <h3>
                Easy Shopping
            </h3>

            <p>
                Browse our collections and order your
                favourite jewellery easily online.
            </p>

        </div>


        <div class="why-card">

            <div class="why-icon">
                💬
            </div>

            <h3>
                Customer Support
            </h3>

            <p>
                Have a question? Contact us and
                our team will be happy to help you.
            </p>

        </div>


    </div>

</section>


<!-- ==================================================
     CALL TO ACTION
     ================================================== -->

<section class="cta">

    <h2>
        Find Something Special ✨
    </h2>

    <p>
        Explore our jewellery collection and discover
        a piece that is perfect for you.
    </p>

    <a href="shop.php"
       class="shop-btn">
        Explore Collection 💎
    </a>

</section>


<!-- ==================================================
     FOOTER
     ================================================== -->

<footer>

    <h3>
        Muthu Jewellers
    </h3>

    <p>
        Elegance That Lasts Forever ✨
    </p>

    <p>
        &copy;
        <?php echo date("Y"); ?>
        <span>Muthu Jewellers</span>.
        All Rights Reserved.
    </p>

</footer>


</body>

</html>