<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Open Session - RestPO POS</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            font-family: 'Inter', sans-serif;
            background-color: #0b1329;
            min-height: 100vh;
        }
        .bg-glow {
            position: fixed;
            width: 450px; height: 450px;
            border-radius: 50%;
            filter: blur(130px);
            opacity: 0.12;
            pointer-events: none;
            z-index: 0;
        }
        .glow-1 { top: -100px; left: -100px; background: #8b5cf6; }
        .glow-2 { bottom: -100px; right: -100px; background: #10b981; }
        .glass-panel {
            background: rgba(255, 255, 255, 0.03);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.08);
            z-index: 10;
        }
    </style>
</head>
<body class="flex items-center justify-center p-4 relative overflow-hidden">
    <!-- Neon Glow Background Elements -->
    <div class="bg-glow glow-1"></div>
    <div class="bg-glow glow-2"></div>

    <div class="glass-panel p-8 rounded-3xl shadow-2xl max-w-md w-full relative overflow-hidden">
        <!-- Accent Line -->
        <div class="absolute top-0 left-0 w-full h-1.5 bg-gradient-to-r from-purple-500 via-indigo-500 to-emerald-500"></div>

        <div class="text-center mb-8">
            <div class="w-16 h-16 bg-purple-500/10 text-purple-400 border border-purple-500/25 rounded-2xl flex items-center justify-center mx-auto mb-4 text-2xl shadow-lg shadow-purple-500/5">
                <i class="fas fa-cash-register"></i>
            </div>
            <h1 class="text-2xl font-extrabold text-white tracking-tight">Open Cash Register</h1>
            <p class="text-slate-400 text-sm mt-2">You must open a sales session before processing invoices.</p>
        </div>

        <form action="/restpo/pos/session/open" method="POST">
            <div class="mb-6">
                <label class="block text-sm font-semibold text-slate-300 mb-2">Opening Cash Balance (<?php echo htmlspecialchars($_SESSION['currency'] ?? '$'); ?>)</label>
                <div class="relative">
                    <div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
                        <span class="text-slate-400 font-bold"><?php echo htmlspecialchars($_SESSION['currency'] ?? '$'); ?></span>
                    </div>
                    <input type="number" step="0.01" name="opening_balance" value="0.00" required 
                           class="pl-10 w-full px-4 py-3 bg-white/5 border border-white/10 rounded-xl focus:ring-2 focus:ring-purple-500 focus:border-transparent outline-none text-lg font-bold text-white transition-all duration-200">
                </div>
            </div>
            
            <button type="submit" class="w-full bg-gradient-to-r from-purple-600 to-blue-600 hover:brightness-110 active:scale-[0.98] text-white font-bold py-3.5 px-4 rounded-xl shadow-lg shadow-purple-900/20 transition-all duration-200 flex items-center justify-center gap-2">
                <i class="fas fa-circle-play text-sm"></i>
                Open POS Session
            </button>
        </form>

        <?php 
        $dashboardUrl = '';
        $linkText = 'Back to Dashboard';
        $linkIcon = 'fa-arrow-left';
        if (isset($_SESSION['role'])) {
            if ($_SESSION['role'] === 'admin') {
                $dashboardUrl = '/restpo/admin/dashboard';
            } elseif ($_SESSION['role'] === 'superadmin') {
                $dashboardUrl = '/restpo/superadmin/dashboard';
            } else {
                $dashboardUrl = '/restpo/logout';
                $linkText = 'Sign Out';
                $linkIcon = 'fa-sign-out-alt';
            }
        }
        if (!empty($dashboardUrl)): 
        ?>
            <div class="mt-8 text-center border-t border-white/5 pt-5 flex flex-col gap-3 items-center">
                <?php if (in_array($_SESSION['role'] ?? '', ['admin', 'superadmin']) && isset($_SESSION['selected_cashier_name'])): ?>
                    <div class="text-xs text-slate-400">
                        Acting as: <span class="text-emerald-400 font-bold"><?php echo htmlspecialchars($_SESSION['selected_cashier_name']); ?></span>
                    </div>
                    <a href="/restpo/pos?cashier_id=change" class="inline-flex items-center gap-2 text-purple-400 hover:text-white text-sm font-semibold transition duration-200 group">
                        <i class="fas fa-users-cog text-xs"></i>
                        Switch Cashier
                    </a>
                <?php endif; ?>
                
                <a href="<?php echo $dashboardUrl; ?>" class="inline-flex items-center gap-2 text-slate-500 hover:text-white text-sm font-semibold transition duration-200 group mt-2">
                    <i class="fas <?php echo $linkIcon; ?> text-xs transition-transform group-hover:-translate-x-1"></i>
                    <?php echo $linkText; ?>
                </a>
            </div>
        <?php endif; ?>
    </div>
</body>
</html>
