<?php
// doctor_login.php
session_start();
require_once 'config.php';

if (isset($_SESSION['doctor_id'])) {
    header('Location: doctor.php');
    exit;
}

$error = '';
if (isset($_POST['login'])) {
    $phone = $_POST['phone'];
    $result = $conn->query("SELECT * FROM doctors WHERE phone = '$phone' AND is_active = 1");
    if ($result && $result->num_rows > 0) {
        $doctor = $result->fetch_assoc();
        $_SESSION['doctor_id'] = $doctor['id'];
        $_SESSION['doctor_name'] = $doctor['name'];
        header('Location: doctor.php');
        exit;
    } else {
        $error = "Doctor not found! Please contact admin.";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Doctor Login</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body{background:linear-gradient(135deg,#1b4332,#2d6a4f);min-height:100vh;display:flex;align-items:center;justify-content:center}
        .login-box{background:#fff;border-radius:20px;padding:40px;box-shadow:0 20px 60px rgba(0,0,0,.3);max-width:400px;width:100%}
    </style>
</head>
<body>
<div class="login-box text-center">
    <i class="fas fa-user-md fa-3x text-success mb-3"></i>
    <h3>Doctor Login</h3>
    <?php if($error): ?><div class="alert alert-danger"><?=$error?></div><?php endif; ?>
    <form method="POST">
        <input type="tel" name="phone" class="form-control mb-3" placeholder="Phone Number" required>
        <button type="submit" name="login" class="btn btn-success w-100">Login</button>
    </form>
    <p class="text-muted small mt-3">Login with your registered phone number</p>
</div>
</body>
</html>