<?php
session_start();

error_reporting(E_ALL);
ini_set('display_errors', 1);

include 'db.php';

$msg = "";

if(isset($_POST['login'])){

    $email = mysqli_real_escape_string($conn,$_POST['email']);
    $password = md5($_POST['password']);

    $sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
    $res = mysqli_query($conn,$sql);

    if($res && mysqli_num_rows($res) > 0){

        $user = mysqli_fetch_assoc($res);

        $_SESSION['user_id'] = $user['id'];
        $_SESSION['user_name'] = $user['name'];
        $_SESSION['user_email'] = $user['email'];

        header("Location: dashboard.php");
        exit;

    }else{
        $msg = "Invalid Email or Password";
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Admin Login | CAPAPP IT SOLUTION</title>

<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet">

<link
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css"
rel="stylesheet">

<style>

/* =========================================================
   GLOBAL
========================================================= */

*{
    box-sizing:border-box;
}

html,
body{
    width:100%;
    min-height:100%;
}

body{

    margin:0;

    font-family:
    "Segoe UI",
    Arial,
    sans-serif;

    background:
    linear-gradient(
        135deg,
        #07111f 0%,
        #0f172a 42%,
        #172554 72%,
        #1d4ed8 100%
    );

    min-height:100vh;

    display:flex;

    align-items:center;

    justify-content:center;

    overflow-x:hidden;

    position:relative;
}


/* =========================================================
   BACKGROUND EFFECTS
========================================================= */

body::before{

    content:"";

    position:fixed;

    width:500px;
    height:500px;

    border-radius:50%;

    background:
    radial-gradient(
        circle,
        rgba(37,99,235,.35),
        transparent 70%
    );

    top:-180px;
    right:-120px;

    filter:blur(10px);

    pointer-events:none;
}

body::after{

    content:"";

    position:fixed;

    width:450px;
    height:450px;

    border-radius:50%;

    background:
    radial-gradient(
        circle,
        rgba(6,182,212,.20),
        transparent 70%
    );

    bottom:-200px;
    left:-150px;

    pointer-events:none;
}


/* =========================================================
   MAIN WRAPPER
========================================================= */

.login-wrapper{

    width:100%;

    max-width:1050px;

    min-height:620px;

    margin:30px;

    display:grid;

    grid-template-columns:
    1fr 1fr;

    background:
    rgba(255,255,255,.08);

    border:
    1px solid rgba(255,255,255,.16);

    border-radius:30px;

    overflow:hidden;

    backdrop-filter:blur(20px);

    -webkit-backdrop-filter:blur(20px);

    box-shadow:
    0 30px 80px rgba(0,0,0,.40);

    position:relative;

    z-index:2;
}


/* =========================================================
   LEFT BRAND PANEL
========================================================= */

.brand-panel{

    position:relative;

    padding:55px;

    display:flex;

    flex-direction:column;

    justify-content:center;

    color:#fff;

    background:
    linear-gradient(
        145deg,
        rgba(15,23,42,.94),
        rgba(30,64,175,.75)
    );

    overflow:hidden;
}


/* Decorative circles */

.brand-panel::before{

    content:"";

    position:absolute;

    width:300px;
    height:300px;

    border-radius:50%;

    border:
    1px solid rgba(255,255,255,.12);

    top:-130px;
    right:-100px;
}

.brand-panel::after{

    content:"";

    position:absolute;

    width:220px;
    height:220px;

    border-radius:50%;

    border:
    1px solid rgba(255,255,255,.10);

    bottom:-100px;
    left:-80px;
}


/* =========================================================
   LOGO ICON
========================================================= */

.logo-icon{

    width:72px;
    height:72px;

    border-radius:20px;

    display:flex;

    align-items:center;

    justify-content:center;

    font-size:34px;

    color:#fff;

    background:
    linear-gradient(
        135deg,
        #2563eb,
        #06b6d4
    );

    box-shadow:
    0 15px 35px rgba(37,99,235,.40);

    margin-bottom:25px;

    position:relative;

    z-index:2;
}


/* =========================================================
   BRAND TEXT
========================================================= */

.brand-panel h1{

    font-size:36px;

    font-weight:800;

    line-height:1.15;

    margin:0 0 15px;

    position:relative;

    z-index:2;
}

.brand-panel h1 span{

    color:#60a5fa;
}

.brand-panel p{

    color:#cbd5e1;

    font-size:15px;

    line-height:1.8;

    max-width:410px;

    margin-bottom:30px;

    position:relative;

    z-index:2;
}


/* =========================================================
   FEATURE LIST
========================================================= */

.feature-list{

    list-style:none;

    padding:0;

    margin:0;

    position:relative;

    z-index:2;
}

.feature-list li{

    display:flex;

    align-items:center;

    gap:12px;

    margin-bottom:15px;

    color:#e2e8f0;

    font-size:14px;
}

.feature-list i{

    width:32px;
    height:32px;

    display:flex;

    align-items:center;

    justify-content:center;

    border-radius:10px;

    background:
    rgba(37,99,235,.25);

    color:#60a5fa;

    font-size:15px;
}


/* =========================================================
   RIGHT LOGIN PANEL
========================================================= */

.login-panel{

    background:#fff;

    padding:55px;

    display:flex;

    align-items:center;

    justify-content:center;
}

.login-content{

    width:100%;

    max-width:390px;
}


/* =========================================================
   LOGIN HEADER
========================================================= */

.login-header{

    margin-bottom:30px;
}

.login-header .mini-icon{

    width:50px;
    height:50px;

    border-radius:15px;

    background:#eff6ff;

    color:#2563eb;

    display:flex;

    align-items:center;

    justify-content:center;

    font-size:22px;

    margin-bottom:18px;
}

.login-header h2{

    margin:0;

    color:#0f172a;

    font-size:29px;

    font-weight:800;
}

.login-header p{

    margin:8px 0 0;

    color:#64748b;

    font-size:14px;
}


/* =========================================================
   ERROR MESSAGE
========================================================= */

.login-error{

    display:flex;

    align-items:center;

    gap:10px;

    padding:13px 15px;

    margin-bottom:20px;

    border-radius:12px;

    color:#991b1b;

    background:#fef2f2;

    border:1px solid #fecaca;

    font-size:13px;

    font-weight:600;
}

.login-error i{

    font-size:18px;
}


/* =========================================================
   FORM GROUP
========================================================= */

.form-group{

    margin-bottom:20px;
}

.form-label{

    display:block;

    color:#334155;

    font-size:13px;

    font-weight:700;

    margin-bottom:8px;
}

.input-box{

    position:relative;
}

.input-box > i:first-child{

    position:absolute;

    left:16px;

    top:50%;

    transform:translateY(-50%);

    color:#94a3b8;

    font-size:17px;

    z-index:2;
}

.input-box input{

    width:100%;

    height:54px;

    border-radius:13px;

    border:1px solid #dbe3ef;

    background:#f8fafc;

    padding:
    0 48px
    0 46px;

    color:#0f172a;

    font-size:14px;

    outline:none;

    transition:.25s;
}

.input-box input::placeholder{

    color:#94a3b8;
}

.input-box input:focus{

    border-color:#2563eb;

    background:#fff;

    box-shadow:
    0 0 0 4px rgba(37,99,235,.10);
}


/* Password eye */

.password-toggle{

    position:absolute;

    right:15px;

    top:50%;

    transform:translateY(-50%);

    border:none;

    background:none;

    color:#64748b;

    cursor:pointer;

    font-size:18px;

    padding:3px;
}

.password-toggle:hover{

    color:#2563eb;
}


/* =========================================================
   EXTRA ROW
========================================================= */

.login-options{

    display:flex;

    align-items:center;

    justify-content:space-between;

    margin:-3px 0 23px;

    font-size:12px;
}

.secure-login{

    display:flex;

    align-items:center;

    gap:6px;

    color:#64748b;
}

.secure-login i{

    color:#16a34a;

    font-size:14px;
}


/* =========================================================
   LOGIN BUTTON
========================================================= */

.btn-login{

    width:100%;

    height:54px;

    border:none;

    border-radius:13px;

    color:#fff;

    font-size:15px;

    font-weight:700;

    cursor:pointer;

    display:flex;

    align-items:center;

    justify-content:center;

    gap:10px;

    background:
    linear-gradient(
        135deg,
        #2563eb,
        #1d4ed8
    );

    box-shadow:
    0 10px 25px rgba(37,99,235,.25);

    transition:.25s;
}

.btn-login:hover{

    transform:translateY(-2px);

    box-shadow:
    0 15px 30px rgba(37,99,235,.35);
}

.btn-login:active{

    transform:translateY(0);
}


/* =========================================================
   FOOTER
========================================================= */

.login-footer{

    margin-top:28px;

    text-align:center;

    color:#94a3b8;

    font-size:11px;

    line-height:1.6;
}

.login-footer strong{

    color:#475569;
}


/* =========================================================
   MOBILE
========================================================= */

@media(max-width:850px){

    .login-wrapper{

        grid-template-columns:1fr;

        max-width:500px;

        min-height:auto;

        margin:20px;
    }

    .brand-panel{

        padding:35px;

        min-height:300px;
    }

    .brand-panel h1{

        font-size:28px;
    }

    .feature-list{

        display:grid;

        grid-template-columns:1fr 1fr;

        gap:5px 15px;
    }

    .feature-list li{

        margin-bottom:8px;
    }

    .login-panel{

        padding:40px 30px;
    }
}


/* =========================================================
   SMALL MOBILE
========================================================= */

@media(max-width:500px){

    body{

        align-items:flex-start;

        padding:15px 0;
    }

    .login-wrapper{

        margin:10px;

        border-radius:22px;
    }

    .brand-panel{

        padding:30px 25px;

        min-height:280px;
    }

    .logo-icon{

        width:60px;
        height:60px;

        border-radius:17px;

        font-size:28px;
    }

    .brand-panel h1{

        font-size:25px;
    }

    .brand-panel p{

        font-size:13px;

        line-height:1.6;

        margin-bottom:20px;
    }

    .feature-list{

        display:block;
    }

    .feature-list li{

        font-size:12px;

        margin-bottom:10px;
    }

    .feature-list i{

        width:28px;
        height:28px;

        border-radius:8px;
    }

    .login-panel{

        padding:32px 22px;
    }

    .login-header h2{

        font-size:25px;
    }

    .login-header{

        margin-bottom:25px;
    }
}

</style>

</head>


<body>


<div class="login-wrapper">


    <!-- =====================================================
         LEFT BRAND PANEL
    ====================================================== -->

    <div class="brand-panel">

        <div class="logo-icon">

            <i class="bi bi-grid-1x2-fill"></i>

        </div>


        <h1>
            CAPAPP
            <span>IT</span>
        </h1>


        <p>
            Welcome to your secure administration panel.
            Manage domains, payments, invoices and business
            operations from one powerful dashboard.
        </p>


        <ul class="feature-list">

            <li>
                <i class="bi bi-globe2"></i>
                <span>Domain Management</span>
            </li>

            <li>
                <i class="bi bi-receipt"></i>
                <span>Invoice Management</span>
            </li>

            <li>
                <i class="bi bi-credit-card"></i>
                <span>Payment Tracking</span>
            </li>

            <li>
                <i class="bi bi-bar-chart-line"></i>
                <span>Business Reports</span>
            </li>

        </ul>

    </div>



    <!-- =====================================================
         RIGHT LOGIN PANEL
    ====================================================== -->

    <div class="login-panel">

        <div class="login-content">


            <div class="login-header">

                <div class="mini-icon">

                    <i class="bi bi-shield-lock-fill"></i>

                </div>

                <h2>
                    Admin Login
                </h2>

                <p>
                    Sign in to continue to your dashboard
                </p>

            </div>


            <?php if($msg){ ?>

                <div class="login-error">

                    <i class="bi bi-exclamation-triangle-fill"></i>

                    <span>
                        <?= htmlspecialchars($msg) ?>
                    </span>

                </div>

            <?php } ?>


            <form method="POST">


                <!-- EMAIL -->

                <div class="form-group">

                    <label class="form-label">
                        Email Address
                    </label>

                    <div class="input-box">

                        <i class="bi bi-envelope-fill"></i>

                        <input
                            type="email"
                            name="email"
                            placeholder="Enter your email"
                            autocomplete="email"
                            required
                        >

                    </div>

                </div>



                <!-- PASSWORD -->

                <div class="form-group">

                    <label class="form-label">
                        Password
                    </label>

                    <div class="input-box">

                        <i class="bi bi-key-fill"></i>

                        <input
                            type="password"
                            name="password"
                            id="password"
                            placeholder="Enter your password"
                            autocomplete="current-password"
                            required
                        >

                        <button
                            type="button"
                            class="password-toggle"
                            onclick="togglePassword()"
                            aria-label="Show password"
                        >

                            <i
                                class="bi bi-eye"
                                id="eyeIcon"
                            ></i>

                        </button>

                    </div>

                </div>



                <!-- SECURITY -->

                <div class="login-options">

                    <div class="secure-login">

                        <i class="bi bi-shield-check"></i>

                        Secure Admin Access

                    </div>

                </div>



                <!-- LOGIN -->

                <button
                    type="submit"
                    name="login"
                    class="btn-login"
                >

                    <i class="bi bi-box-arrow-in-right"></i>

                    Login to Dashboard

                </button>


            </form>


            <div class="login-footer">

                <strong>CAPAPP IT SOLUTION PRIVATE LIMITED</strong>
                <br>

                Secure Administration Panel

            </div>


        </div>

    </div>

</div>



<script>

/* =========================================================
   SHOW / HIDE PASSWORD
========================================================= */

function togglePassword(){

    const password =
        document.getElementById("password");

    const eyeIcon =
        document.getElementById("eyeIcon");


    if(password.type === "password"){

        password.type = "text";

        eyeIcon.classList.remove("bi-eye");

        eyeIcon.classList.add("bi-eye-slash");

    }else{

        password.type = "password";

        eyeIcon.classList.remove("bi-eye-slash");

        eyeIcon.classList.add("bi-eye");

    }

}

</script>


</body>
</html>