<?php
session_start();
include 'config/db.php';
include 'config/function.php';
include 'config/config.php';



$err = $msg = ""; 

$email = $password = "";
    
if (isset($_POST['login'])) {
    $valid = 1;
     if (empty($_POST["email"])) {
        $valid = 0;
        $err = "Email is required";
        echo "<script>alert('Email is required');</script>";
      } else {
        $email = test_input($_POST["email"]);      
      }
      
      
      if (empty($_POST["pwrd"])) {
        $valid = 0;
        $err = "Password is required";
        echo "<script>alert('Password is required');</script>";
      } else {
        $password = test_input($_POST["pwrd"]);
      }

    if($valid == 1){
        $sql = mysqli_query($link, "SELECT * FROM users WHERE email = '$email' ");
        if(mysqli_num_rows($sql) > 0){
            $data = mysqli_fetch_assoc($sql);
            $pass = $data['password'];
            $email = $data['email'];

            if ($password != $pass) {
                $err = "Invalid Password";
                echo "<script>alert('Invalid Password');</script>";
            }else{
                $_SESSION['USER_LOGIN'] = $email;
                echo "<script>alert('successfully! Redirecting...'); window.location.href = 'dashboard.php';</script>";
            }
        
        }else{
            $err = "Invalid Email Address";
            echo "<script>alert('Invalid Email Address');</script>";
        }
    }
    
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}


?>

<!doctype html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="cQVhgmyWj0trJD4ouNo88EZb1Awqc1pjyoKQ5ngO">

    <title><?php echo $sitename ?></title>

    <link rel="icon" type="image/x-icon"
        href="https://celebbookingsmeetups.com/storage/app/public/settings/hCE56TZD7q9VZC8QUO0t6hcFfGSzlbqnrmAHQPDz.png">

    <!-- Load critical CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap">

    <!-- Load app.css -->
    <!-- <link rel="stylesheet" href="http://celebbookingsmeetups.com/css/app.css"> -->

    <!-- Preload app.js -->
    <link rel="preload" href="http://celebbookingsmeetups.com/js/app.js" as="script">

    <!-- Preconnect to external domains -->
    <link rel="preconnect" href="https://cdn.jsdelivr.net">
    <link rel="preconnect" href="https://cdnjs.cloudflare.com">
    <link rel="dns-prefetch" href="https://cdn.jsdelivr.net">
    <link rel="dns-prefetch" href="https://cdnjs.cloudflare.com">

    <!-- Preload critical font -->
    <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/webfonts/fa-solid-900.woff2"
        as="font" type="font/woff2" crossorigin>

    <style>
        /* Lazy Loading Styles */
        .lazy {
            opacity: 0;
            transition: opacity 0.3s ease-in-out;
            background: #f5f7fa;
        }

        .lazy.loaded {
            opacity: 1;
        }

        .lazy-spinner {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 40px;
            height: 40px;
            border: 3px solid #f3f3f3;
            border-top: 3px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            z-index: 1;
        }

        @keyframes spin {
            0% {
                transform: translate(-50%, -50%) rotate(0deg);
            }

            100% {
                transform: translate(-50%, -50%) rotate(360deg);
            }
        }

        .lazy-container {
            position: relative;
            background: #f5f7fa;
            overflow: hidden;
        }

        .lazy-container img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        /* Responsive Images */
        img {
            max-width: 100%;
            height: auto;
        }

        :root {
            --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            --warning-gradient: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
            --dark-gradient: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
            --glass-bg: rgba(255, 255, 255, 0.1);
            --glass-border: rgba(255, 255, 255, 0.2);
            --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
            --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.15);
            --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.2);
        }

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

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            line-height: 1.6;
        }

        /* Modern Navbar */
        .navbar-modern {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: var(--shadow-sm);
            padding: 1rem 0;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            background: var(--primary-gradient);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .nav-link {
            font-weight: 500;
            color: #4a5568 !important;
            transition: all 0.3s ease;
            position: relative;
            margin: 0 0.5rem;
        }

        .nav-link:hover {
            color: #667eea !important;
        }

        .nav-link::before {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -5px;
            left: 50%;
            background: var(--primary-gradient);
            transition: all 0.3s ease;
            transform: translateX(-50%);
        }

        .nav-link:hover::before {
            width: 100%;
        }

        /* Modern Cards */
        .card-modern {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 20px;
            box-shadow: var(--shadow-md);
            transition: all 0.3s ease;
            overflow: hidden;
        }

        .card-modern:hover {
            transform: translateY(-8px);
            box-shadow: var(--shadow-lg);
        }

        /* Modern Buttons */
        .btn-modern {
            border: none;
            border-radius: 12px;
            padding: 0.75rem 1.5rem;
            font-weight: 600;
            text-transform: none;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .btn-primary-modern {
            background: var(--primary-gradient);
            color: white;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        }

        .btn-primary-modern:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
            color: white;
        }

        .btn-secondary-modern {
            background: rgba(255, 255, 255, 0.9);
            color: #4a5568;
            backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .btn-secondary-modern:hover {
            background: rgba(255, 255, 255, 1);
            transform: translateY(-2px);
            color: #4a5568;
        }

        /* Glass Cards */
        .glass-card {
            background: var(--glass-bg);
            backdrop-filter: blur(20px);
            border: 1px solid var(--glass-border);
            border-radius: 20px;
            padding: 2rem;
        }

        /* Modern Footer */
        .footer-modern {
            background: var(--dark-gradient);
            color: white;
            padding: 3rem 0 1rem;
            margin-top: 4rem;
        }

        /* Animations */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .fade-in-up {
            animation: fadeInUp 0.6s ease forwards;
        }

        /* Custom Scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
        }

        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }

        ::-webkit-scrollbar-thumb {
            background: var(--primary-gradient);
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: #555;
        }

        /* Mobile Responsiveness */
        @media (max-width: 768px) {
            .glass-card {
                padding: 1.5rem;
            }

            .btn-modern {
                padding: 0.6rem 1.2rem;
            }
        }
    </style>
</head>


<body class="d-flex flex-column h-100">
    <nav class="navbar navbar-expand-lg navbar-modern fixed-top">
        <div class="container">
            <a class="navbar-brand d-flex align-items-center" href="index.php">
                <img src="logo.png"
                    alt="Celebrity Management Platform" class="header-logo me-2"
                    style="max-height: 40px; width: auto; max-width: 180px; object-fit: contain;">
                <span class="visually-hidden">Celebrity Management Platform</span>
            </a>

            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="index.php">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="celebrities.php">Celebrities</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="contact.php">Contact</a>
                    </li>
                </ul>
                
                <?php
                    if (!isset($_SESSION["USER_LOGIN"])){
                ?>
                
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="login.php">Login</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link btn btn-primary-modern text-white ms-2 px-3"
                            href="register.php">Get Started</a>
                    </li>
                </ul>
                
                <?php }else{ ?>

                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="navbarDropdown"
                            role="button" data-bs-toggle="dropdown">
                            <div class="bg-primary rounded-circle d-flex align-items-center justify-content-center me-2"
                                style="width: 32px; height: 32px;">
                                <i class="fas fa-user text-white"></i>
                            </div>
                           <?php echo $name ?>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end shadow-lg" style="min-width: 220px;">
                            <li class="px-3 py-2">
                                <div class="d-flex align-items-center">
                                    <div class="bg-primary rounded-circle d-flex align-items-center justify-content-center me-2"
                                        style="width: 40px; height: 40px;">
                                        <i class="fas fa-user text-white"></i>
                                    </div>
                                    <div>
                                        <div class="fw-bold"><?php echo $name ?></div>
                                        <small class="text-muted"><?php echo $email ?></small>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <hr class="dropdown-divider my-2">
                            </li>
                            <li><a class="dropdown-item" href="profile.php"><i
                                        class="fas fa-user-circle me-2"></i>My Profile</a></li>
                            <li><a class="dropdown-item" href="dashboard.php"><i
                                        class="fas fa-tachometer-alt me-2"></i>Dashboard</a></li>
                            <li><a class="dropdown-item" href="my-fan-cards.php"><i
                                        class="fas fa-id-card me-2"></i>My Fan Cards</a></li>
                            <li><a class="dropdown-item" href="my-transactions.php"><i
                                        class="fas fa-exchange-alt me-2"></i>Transactions</a></li>
                            <li>
                                <hr class="dropdown-divider">
                            </li>
                            <li>
                                <a class="dropdown-item text-danger" href="logout.php"
                                    onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
                                    <i class="fas fa-sign-out-alt me-2"></i>Logout
                                </a>
                                <form id="logout-form" action="logout.php" method="POST"
                                    class="d-none">
                                    <input type="hidden" name="_token" value="cQVhgmyWj0trJD4ouNo88EZb1Awqc1pjyoKQ5ngO"
                                        autocomplete="off">
                                </form>
                            </li>
                        </ul>
                    </li>
                </ul>
                <?php } ?>
            </div>
        </div>
    </nav>

    <main class="flex-grow-1" style="padding-top: 80px;">
        
        
        <style>
    .auth-container {
        min-height: calc(100vh - 160px);
        display: flex;
        align-items: center;
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        padding: 2rem 0;
    }

    .auth-card {
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 25px;
        box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);
        overflow: hidden;
    }

    .auth-header {
        background: white;
        color: white;
        padding: 2rem;
        text-align: center;
        position: relative;
    }

    .auth-header::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: url('data:image/svg+xml,<svg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><g fill="%23ffffff" fill-opacity="0.1"><circle cx="12" cy="12" r="2"/><circle cx="48" cy="12" r="2"/><circle cx="12" cy="48" r="2"/><circle cx="48" cy="48" r="2"/></g></g></svg>');
    }

    .auth-icon {
        width: 80px;
        height: 80px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 1rem;
        font-size: 2rem;
        position: relative;
        z-index: 2;
    }

    .auth-title {
        font-size: 1.75rem;
        font-weight: 700;
        margin: 0;
        position: relative;
        z-index: 2;
    }

    .auth-subtitle {
        color: purple;
        opacity: 0.9;
        margin-top: 0.5rem;
        position: relative;
        z-index: 2;
    }

    .auth-body {
        padding: 2.5rem;
    }

    .form-floating {
        position: relative;
        margin-bottom: 1.5rem;
    }

    .form-floating .form-control {
        background: rgba(255, 255, 255, 0.8);
        border: 2px solid transparent;
        border-radius: 15px;
        padding: 1.5rem 1rem 0.75rem;
        transition: all 0.3s ease;
        height: auto;
    }

    .form-floating .form-control:focus {
        border-color: #667eea;
        box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        background: rgba(255, 255, 255, 1);
    }

    /* Password field styling */
    .password-field .form-control {
        padding-right: 50px !important;
    }
    
    .password-toggle-btn {
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: #6c757d;
        cursor: pointer;
        z-index: 100;
        padding: 8px;
        font-size: 16px;
        transition: color 0.2s ease;
        outline: none;
    }
    
    .password-toggle-btn:hover {
        color: #667eea;
    }
    
    .password-toggle-btn:focus {
        outline: none;
        color: #667eea;
    }

    .form-floating label {
        padding: 1rem;
        color: #6c757d;
        font-weight: 500;
    }

    .form-check {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        margin: 1.5rem 0;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        border-radius: 6px;
        border: 2px solid #d1d5db;
        transition: all 0.2s ease;
    }

    .form-check-input:checked {
        background-color: #667eea;
        border-color: #667eea;
    }

    .form-check-label {
        font-weight: 500;
        color: #4a5568;
        cursor: pointer;
    }

    .btn-auth-primary {
        background: var(--primary-gradient);
        border: none;
        color: white;
        font-weight: 600;
        padding: 1rem 2rem;
        border-radius: 12px;
        transition: all 0.3s ease;
        width: 100%;
        font-size: 1.1rem;
    }

    .btn-auth-primary:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
        color: white;
    }

    .btn-auth-link {
        color: #667eea;
        text-decoration: none;
        font-weight: 500;
        transition: all 0.2s ease;
    }

    .btn-auth-link:hover {
        color: #5a67d8;
        text-decoration: underline;
    }

    .auth-divider {
        display: flex;
        align-items: center;
        margin: 2rem 0;
        color: #9ca3af;
        font-size: 0.875rem;
    }

    .auth-divider::before,
    .auth-divider::after {
        content: '';
        flex: 1;
        height: 1px;
        background: #e5e7eb;
    }

    .auth-divider span {
        padding: 0 1rem;
        background: white;
    }

    .auth-footer {
        text-align: center;
        padding: 1.5rem 2.5rem;
        background: #f8fafc;
        border-top: 1px solid #e2e8f0;
    }

    .social-login {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .btn-social {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        border: 2px solid #e2e8f0;
        border-radius: 10px;
        background: white;
        color: #4a5568;
        text-decoration: none;
        font-weight: 500;
        transition: all 0.2s ease;
    }

    .btn-social:hover {
        border-color: #cbd5e0;
        transform: translateY(-1px);
        color: #2d3748;
    }

    .error-message {
        color: #e53e3e;
        font-size: 0.875rem;
        margin-top: 0.5rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    /* Loading spinner */
    .spinner-border-sm {
        width: 1rem;
        height: 1rem;
        border-width: 0.125em;
    }

    @media (max-width: 768px) {
        .auth-container {
            padding: 1rem;
            min-height: calc(100vh - 120px);
        }
        
        .auth-body {
            padding: 2rem 1.5rem;
        }
        
        .auth-header {
            padding: 1.5rem;
        }
        
        .auth-icon {
            width: 60px;
            height: 60px;
            font-size: 1.5rem;
        }
        
        .auth-title {
            font-size: 1.5rem;
        }
        
        .social-login {
            grid-template-columns: 1fr;
        }
    }
</style>

<div class="auth-container">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6 col-lg-5">
                <div class="auth-card">
                                        
                    <div class="auth-header">
                                                    <div class="auth-logo mb-3" style="max-height: 80px; display: flex; align-items: center; justify-content: center;">
                                <img src="logo.png" alt="Celebrity Management Platform" style="max-height: 100%; max-width: 100%; width: auto; object-fit: contain;">
                            </div>
                            
                                                
                                                
                        <p class="auth-subtitle mb-0">Sign in to your account to continue</p>
                    </div>

                    <div class="auth-body">
                        <form method="POST" action="" id="loginForm">
                            <input type="hidden" name="_token" value="zuXNHNzUyS1eZwQz2XskXw3ijpDWGNUfuAzRIeQO" autocomplete="off">
                            <div class="form-floating">
                                <input id="email" 
                                       type="email" 
                                       class="form-control " 
                                       name="email" 
                                       value="" 
                                       required 
                                       autocomplete="email" 
                                       autofocus
                                       placeholder="Enter your email">
                                <label for="email">Email Address</label>
                                                            </div>

                            <div class="form-floating" style="position: relative !important; margin-bottom: 1.5rem;">
                                <input id="password" 
                                       type="password" 
                                       class="form-control " 
                                       name="pwrd" 
                                       required 
                                       autocomplete="current-password"
                                       style="padding-right: 60px !important; padding-left: 1rem !important; padding-top: 1.5rem !important; padding-bottom: 0.75rem !important;"
                                       placeholder="Enter your password">
                                <label for="password" style="padding: 1rem !important;">Password</label>
                                
                                <!-- BULLETPROOF TOGGLE BUTTON -->
                                <span onclick="
                                    var input = document.getElementById('password');
                                    var icon = this.querySelector('i');
                                    if (input && icon) {
                                        if (input.type === 'password') {
                                            input.type = 'text';
                                            icon.className = 'fas fa-eye-slash';
                                            console.log('Login password shown');
                                        } else {
                                            input.type = 'password';
                                            icon.className = 'fas fa-eye';
                                            console.log('Login password hidden');
                                        }
                                    } else {
                                        console.error('Elements not found');
                                    }
                                " style="
                                    position: absolute !important;
                                    right: 15px !important;
                                    top: 50% !important;
                                    transform: translateY(-50%) !important;
                                    cursor: pointer !important;
                                    z-index: 9999 !important;
                                    background: none !important;
                                    border: none !important;
                                    padding: 8px !important;
                                    color: #6c757d !important;
                                    font-size: 16px !important;
                                    display: block !important;
                                    pointer-events: auto !important;
                                ">
                                    <i class="fas fa-eye"></i>
                                </span>
                                
                                                            </div>

                            <div class="form-check">
                                <input class="form-check-input" 
                                       type="checkbox" 
                                       name="remember" 
                                       id="remember" 
                                       >
                                <label class="form-check-label" for="remember">
                                    Remember me for 30 days
                                </label>
                            </div>

                            <button name="login" type="submit" class="btn btn-auth-primary">
                                <i class="fas fa-sign-in-alt me-2"></i>
                                Sign In
                            </button>
                        </form>

                        <!--<div class="auth-divider">-->
                        <!--    <span>Or continue with</span>-->
                        <!--</div>-->

                        <!--<div class="social-login">-->
                        <!--    <a href="#" class="btn-social">-->
                        <!--        <i class="fab fa-google text-danger"></i>-->
                        <!--        Google-->
                        <!--    </a>-->
                        <!--    <a href="#" class="btn-social">-->
                        <!--        <i class="fab fa-github text-dark"></i>-->
                        <!--        GitHub-->
                        <!--    </a>-->
                        <!--</div>-->

                        <!--<div class="text-center">-->
                        <!--                                    <a class="btn-auth-link" href="http://celebbookingsmeetups.com/password/reset">-->
                        <!--            <i class="fas fa-key me-1"></i>-->
                        <!--            Forgot your password?-->
                        <!--        </a>-->
                        <!--                            </div>-->
                    </div>

                    <div class="auth-footer">
                        <p class="mb-0">
                            Don't have an account? 
                            <a href="register.php" class="btn-auth-link">
                                <strong>Create one now</strong>
                            </a>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
    </main>
<?php
include 'header.php'; 

?>