<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
$projectRoot = dirname(__DIR__);
require_once $projectRoot . '/config/database.php';

if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'teacher') { 
    header("Location: ../auth/login.php"); 
    exit(); 
}

$exam_id = $_GET['id'] ?? null;
if (!$exam_id) {
    header("Location: cbt_create.php");
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Question Entry Method | School System</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root { 
            --primary: #3498db; 
            --accent: #2ecc71; 
            --dark: #1a252f; 
            --bg: #f4f7f6; 
            --white: #ffffff; 
            --text-muted: #7f8c8d;
        }
        
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: var(--bg); margin: 0; padding: 40px 20px; color: #333; }

        .container { max-width: 900px; margin: 0 auto; }

        /* Stepper Header */
        .stepper { display: flex; justify-content: space-between; margin-bottom: 60px; position: relative; max-width: 700px; margin-left: auto; margin-right: auto; }
        .stepper::before { content: ''; position: absolute; top: 20px; left: 0; right: 0; height: 3px; background: #e0e0e0; z-index: 1; }
        .step { position: relative; z-index: 2; background: #e0e0e0; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; color: white; transition: 0.3s; }
        .step.completed { background: var(--accent); }
        .step.active { background: var(--primary); transform: scale(1.1); box-shadow: 0 0 15px rgba(52, 152, 219, 0.4); }
        .step-label { position: absolute; top: 48px; font-size: 11px; color: var(--text-muted); white-space: nowrap; width: 100px; text-align: center; left: 50%; transform: translateX(-50%); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }

        .choice-container { text-align: center; }
        .choice-container h2 { font-size: 32px; color: var(--dark); margin-bottom: 10px; font-weight: 800; }
        .choice-container p.subtitle { color: var(--text-muted); margin-bottom: 50px; font-size: 16px; }

        .options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 30px; }

        /* Sophisticated Card Design */
        .option-card { 
            background: var(--white); 
            padding: 60px 40px; 
            border-radius: 24px; 
            box-shadow: 0 10px 40px rgba(0,0,0,0.04); 
            border: 1px solid rgba(0,0,0,0.05); 
            transition: all 0.4s ease;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
        }

        /* The top color bar is always visible but grows on hover */
        .option-card::before {
            content: '';
            position: absolute;
            top: 0; left: 0; width: 100%; height: 6px;
            transition: 0.3s;
            border-radius: 24px 24px 0 0;
        }
        .option-card.manual::before { background: var(--primary); }
        .option-card.bulk::before { background: var(--accent); }

        .option-card:hover { transform: translateY(-10px); box-shadow: 0 20px 50px rgba(0,0,0,0.1); }

        /* Icon Container Styling - Matches the generated look */
        .icon-circle {
            width: 110px;
            height: 110px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 30px;
            position: relative;
            transition: 0.4s;
        }

        .manual .icon-circle { background: rgba(52, 152, 219, 0.1); color: var(--primary); }
        .bulk .icon-circle { background: rgba(46, 204, 113, 0.1); color: var(--accent); }

        .icon-circle i { font-size: 45px; z-index: 2; }

        /* Always visible secondary decorative ring */
        .icon-circle::after {
            content: '';
            position: absolute;
            width: 130px;
            height: 130px;
            border-radius: 50%;
            border: 2px dashed;
            opacity: 0.2;
            transition: 0.5s;
        }
        .manual .icon-circle::after { border-color: var(--primary); }
        .bulk .icon-circle::after { border-color: var(--accent); }

        .option-card:hover .icon-circle::after { transform: rotate(90deg); opacity: 0.5; }

        .option-card h3 { font-size: 24px; color: var(--dark); margin: 0 0 15px 0; font-weight: 700; }
        .option-card p { color: var(--text-muted); font-size: 15px; line-height: 1.7; margin-bottom: 35px; flex-grow: 1; }

        .btn { 
            text-decoration: none; 
            padding: 16px 30px; 
            border-radius: 14px; 
            font-weight: 700; 
            transition: 0.3s; 
            width: 100%;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            font-size: 15px;
        }

        .btn-manual { background: var(--primary); color: white; box-shadow: 0 4px 15px rgba(52, 152, 219, 0.2); }
        .btn-manual:hover { background: #2980b9; transform: scale(1.02); }

        .btn-bulk { background: var(--accent); color: white; box-shadow: 0 4px 15px rgba(46, 204, 113, 0.2); }
        .btn-bulk:hover { background: #27ae60; transform: scale(1.02); }

        .back-link { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 30px; color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 600; transition: 0.3s; }
        .back-link:hover { color: var(--primary); }

        @media (max-width: 768px) {
            .options-grid { grid-template-columns: 1fr; }
            .stepper { display: none; }
        }
    </style>
</head>
<body>

<div class="container">
    <a href="cbt_create.php" class="back-link"><i class="fa fa-arrow-left"></i> Back to Exam Setup</a>

    <div class="stepper">
        <div class="step completed"><i class="fa fa-check"></i> <span class="step-label">Exam Info</span></div>
        <div class="step active">2 <span class="step-label">Method</span></div>
        <div class="step">3 <span class="step-label">Questions</span></div>
        <div class="step">4 <span class="step-label">Finalize</span></div>
    </div>

    <div class="choice-container">
        <h2>Question Entry Method</h2>
        <p class="subtitle">Select your preferred way to build this exam.</p>
        
        <div class="options-grid">
            <div class="option-card manual">
                <div class="icon-circle">
                    <i class="fa fa-keyboard"></i>
                </div>
                <h3>Manual Entry</h3>
                <p>Perfect for custom quizzes. Create questions one-by-one with full control over images and formatting.</p>
                <a href="manual_entry.php?id=<?= $exam_id ?>" class="btn btn-manual">
                    Start Manual Entry <i class="fa fa-arrow-right"></i>
                </a>
            </div>

            <div class="option-card bulk">
                <div class="icon-circle">
                    <i class="fa fa-file-csv"></i>
                </div>
                <h3>Bulk CSV Upload</h3>
                <p>The fastest way to populate your exam. Download our official template, fill in your data, and upload instantly.</p>
                <a href="bulk_upload.php?id=<?= $exam_id ?>" class="btn btn-bulk">
                    <i class="fa fa-upload"></i> Upload CSV File
                </a>
            </div>
        </div>
    </div>
</div>

</body>
</html>