<?php 
use App\Models\Settings;
$appConfig = new Settings();
$appName = $appConfig->get('company_name', 'Finance Manager');
$logo = $appConfig->get('logo');
$logoUrl = $logo ? $this->baseUrl('/' . ltrim($logo, '/')) : null;
$pageTitle = 'Client Portal';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($appName) ?> - Client Login</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="<?= $this->baseUrl('/css/style.css') ?>">
    <style>
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
            min-height: 100vh;
        }
        .login-wrapper {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .login-card {
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 20px 50px rgba(0,0,0,0.08);
        }
        .brand-panel {
            background: linear-gradient(135deg, #0f172a, #1e293b);
            color: #fff;
            padding: 3rem 2rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
        .form-panel {
            background: #fff;
            padding: 3rem 2.5rem;
        }
        .brand-logo {
            max-height: 50px;
            margin-bottom: 1.5rem;
        }
        .brand-name {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--gold-light);
        }
        .brand-tagline {
            color: #94a3b8;
            font-size: 0.95rem;
        }
    </style>
</head>
<body>
<div class="login-wrapper">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8">
                <div class="login-card card border-0">
                    <div class="row g-0">
                        <!-- Branding side -->
                        <div class="col-md-5 brand-panel text-center text-md-start">
                            <?php if ($logoUrl): ?>
                                <img src="<?= $logoUrl ?>" alt="Logo" class="brand-logo">
                            <?php else: ?>
                                <div style="font-size: 3rem;">💰</div>
                            <?php endif; ?>
                            <h2 class="brand-name mt-2"><?= htmlspecialchars($appName) ?></h2>
                            <p class="brand-tagline mt-3">Access your account, track balances, and view transaction history.</p>
                            <div class="mt-4 d-none d-md-block">
                                <small class="text-secondary">Secure Client Portal</small>
                            </div>
                        </div>
                        <!-- Login form side -->
                        <div class="col-md-7 form-panel">
                            <h3 class="mb-4 fw-bold">Sign In</h3>
                            <?php if (isset($_SESSION['error'])): ?>
                                <div class="alert alert-danger"><?= htmlspecialchars($_SESSION['error']); unset($_SESSION['error']); ?></div>
                            <?php endif; ?>
                            <?php if (isset($_SESSION['success'])): ?>
                                <div class="alert alert-success"><?= htmlspecialchars($_SESSION['success']); unset($_SESSION['success']); ?></div>
                            <?php endif; ?>
                            <form method="post" action="<?= $this->baseUrl('/client/login') ?>">
                                <div class="mb-3">
                                    <label class="form-label">Username or Client Code</label>
                                    <input type="text" name="username" class="form-control form-control-lg" required autofocus>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Password</label>
                                    <input type="password" name="password" class="form-control form-control-lg" required>
                                </div>
                                <button type="submit" class="btn btn-primary btn-lg w-100 mt-3">Login</button>
                            </form>
                            <div class="text-center mt-3">
                                <a href="<?= $this->baseUrl('/client/forgot-password') ?>" class="text-decoration-none">Forgot Password?</a>
                            </div>
                            <div class="text-center mt-3">
                                <small class="text-muted">Need help? Contact your administrator.</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>