<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ob_start();
require_once('includes/load.php');

// Redirect user to home.php if already logged in
if ($session->isUserLoggedIn(true)) {
    redirect('home.php', false);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - Resource Planning System <?php echo ENVIRONMENT; ?></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
    <style>
        body {
            background-image: url('images/logo.png');
            background-size: 50%; /* Mengurangi ukuran logo */
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: center;
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column; /* Mengubah arah flexbox menjadi kolom */
            justify-content: flex-start;
            align-items: flex-start;
            min-height: 100vh;
            position: relative;
        }

        /* --- STYLING HEADER AT THE TOP --- */
        .header-text {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: black;
            font-size: 2.5rem;
            font-family: 'Times New Roman', Times, serif;
            font-weight: bold;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
            text-align: center;
        }
        /* --- END OF STYLING HEADER AT THE TOP --- */


        /* --- STYLING LOGIN PAGE (KEMBALI KE POSISI SAMPING KANAN) --- */
        .login-page {
            background-color: rgba(0, 0, 0, 0.7);
            padding: 25px;
            border-radius: 10px;
            color: white;
            box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.6);
            width: 100%;
            max-width: 400px;
            box-sizing: border-box;
            text-align: center;
            position: absolute;
            top: 50%;
            right: 20px;
            transform: translateY(-50%);
        }
        .login-page h1, .login-page h4, .login-page label, .login-page .btn {
            color: white;
        }
        .login-page h1 {
            margin-bottom: 10px;
            font-size: 24px;
        }
        .login-page h4 {
            margin-bottom: 20px;
            font-size: 18px;
        }
        .form-group {
            margin-bottom: 15px;
            text-align: left;
        }
        .form-control {
            width: 100%;
            padding: 10px;
            margin-top: 5px;
            border: none;
            border-radius: 5px;
            box-sizing: border-box;
        }
        .btn {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 5px;
            background-color: #dc3545;
            color: white;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .btn:hover {
            background-color: #c82333;
        }
        .marquee-container {
            overflow: hidden;
            white-space: nowrap;
            box-sizing: border-box;
            width: 100%;
            margin-bottom: 20px;
        }
        .marquee {
            display: inline-block;
            padding-left: 100%;
            animation: marquee 15s linear infinite;
        }
        @keyframes marquee {
            0% { transform: translate(0, 0); }
            100% { transform: translate(-100%, 0); }
        }
        .marquee span {
            font-size: 16px;
            color: white;
        }
        /* --- END OF STYLING LOGIN PAGE --- */


        /* --- STYLING CONTACT INFO AT THE BOTTOM --- */
        .contact-info-bottom {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            text-align: center;
            color: black;
            font-size: 14px;
        }
        .contact-info-bottom a {
            color: black;
            text-decoration: underline;
        }
        /* --- END OF STYLING CONTACT INFO AT THE BOTTOM --- */

        
        /* Media queries untuk responsivitas */
        @media (max-width: 768px) {
            body {
                padding: 10px;
                background-size: 70%;
                justify-content: center;
                align-items: center;
            }
            .header-text {
                position: static;
                transform: none;
                margin-bottom: 20px;
            }
            .login-page {
                position: static;
                transform: none;
                margin-right: 0;
                margin: auto;
                max-width: 100%;
            }
            .contact-info-bottom {
                position: static;
                transform: none;
                margin-top: 20px;
            }
            .header-text {
                font-size: 2rem;
            }
            .contact-info-bottom {
                font-size: 12px;
            }
        }
        
        @media (max-width: 480px) {
            .login-page {
                padding: 15px;
            }
            body {
                background-size: 80%;
            }
            .header-text {
                font-size: 1.5rem;
            }
            .contact-info-bottom {
                font-size: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="header-text">
        General Contractor and Supplier
    </div>

    <div class="login-page">
        <div class="marquee-container">
            <div class="marquee">
                <span>KANAKA RESOURCE SYSTEM</span>
            </div>
        </div>
        <?php echo display_msg($msg); ?>
        <?php if (!empty($errors)): ?>
            <div class="alert alert-danger">
                <ul>
                    <?php foreach ($errors as $error): ?>
                        <li><?php echo htmlspecialchars($error); ?></li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endif; ?>
        <h1>Login Panel</h1>
        <h4>Resource Planning System <?php echo ENVIRONMENT; ?></h4>
        <form method="post" action="auth.php" class="clearfix">
            <div class="form-group">
                <label for="username" class="control-label">Username</label>
                <input type="text" class="form-control" name="username" placeholder="Username" required>
            </div>
            <div class="form-group">
                <label for="Password" class="control-label">Password</label>
                <input type="password" name="password" class="form-control" placeholder="Password" required>
            </div>
            <div class="form-group">
                <button type="submit" class="btn">Login</button>
            </div>
        </form>
    </div>

    <div class="contact-info-bottom">
        <p><strong>KANAKA HOLDING</strong></p>
        <p>📞 <strong>(+62) 31-99114953 / (+62) 81-1345-4862</strong></p>
        <p>📬 <strong><a href="mailto:info@kanakapinasthikasentosa.com">info@kanakapinasthikasentosa.com</a></strong></p>
    </div>
</body>
</html>