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

if (!isset($_SESSION['user_id'])) {
    header('Location: ../login.php');
    exit;
}

// Add Doctor
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $mobile = trim($_POST['mobile']);
    $city = trim($_POST['city']);
    $specialization = trim($_POST['specialization']);

    if ($name !== '') {
        $stmt = $conn->prepare("
            INSERT INTO doctors (name, mobile, city, specialization)
            VALUES (?, ?, ?, ?)
        ");
        $stmt->bind_param("ssss", $name, $mobile, $city, $specialization);
        $stmt->execute();

        header("Location: doctors.php?msg=added");
        exit;
    }
}

// Fetch Doctors
$result = $conn->query("SELECT * FROM doctors ORDER BY id DESC");
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Doctor Management</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">

<style>
:root{
--bg:#eef3f9;
--card:#ffffff;
--text:#0f172a;
--muted:#64748b;
--border:#e2e8f0;

--primary:#374155;
--primary-dark:#1f2937;

--shadow:0 12px 30px rgba(15,23,42,.08);
--radius:18px;
}

body{
margin:0;
font-family:Inter,Arial;
background:linear-gradient(135deg,#eef3f9,#f8fafc);
color:var(--text);
}

/* ===== LAYOUT ===== */
.main-content{
margin-left:260px;
padding:40px 20px;
}

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

/* ===== HEADER ===== */
.page-header{
display:flex;
align-items:center;
gap:16px;
background:#fff;
padding:20px;
border-radius:16px;
box-shadow:var(--shadow);
margin-bottom:20px;
border:1px solid var(--border);
}

.page-header i{
width:50px;
height:50px;
border-radius:14px;
background:linear-gradient(135deg,#374155,#1f2937);
color:#fff;
display:flex;
align-items:center;
justify-content:center;
font-size:20px;
}

.page-header h1{
margin:0;
font-size:24px;
font-weight:900;
color:#374155;
}

.page-header p{
margin:4px 0 0;
font-size:13px;
color:var(--muted);
}

/* ===== CARD ===== */
.card{
background:#fff;
border-radius:16px;
padding:24px;
box-shadow:var(--shadow);
border:1px solid var(--border);
transition:.3s;
}

.card:hover{
transform:translateY(-3px);
}

/* ===== FORM ===== */
.form-group{
margin-bottom:16px;
}

.form-group label{
font-size:13px;
font-weight:700;
color:#374155;
margin-bottom:6px;
display:block;
}

.form-group input{
width:100%;
padding:12px 14px;
border-radius:12px;
border:1px solid var(--border);
font-size:14px;
transition:.25s;
}

.form-group input:focus{
border-color:#374155;
box-shadow:0 0 0 3px rgba(55,65,85,.1);
outline:none;
}

/* ===== BUTTON ===== */
.btn{
background:linear-gradient(135deg,#374155,#1f2937);
color:#fff;
border:none;
padding:12px 20px;
border-radius:30px;
cursor:pointer;
display:inline-flex;
align-items:center;
gap:8px;
font-weight:700;
transition:.3s;
}

.btn:hover{
transform:translateY(-2px);
box-shadow:0 10px 20px rgba(0,0,0,.15);
}

/* ===== MESSAGE ===== */
.message{
background:#dcfce7;
color:#166534;
padding:12px 14px;
border-radius:10px;
margin-bottom:15px;
font-weight:600;
}

/* ===== CENTER BUTTON ===== */
.btn-center{
text-align:center;
margin-top:10px;
}

/* ===== RESPONSIVE ===== */
@media(max-width:900px){
.main-content{margin-left:0;}
}
</style>
</head>

<body>

<?php if (file_exists('rasidebar.php')) include 'rasidebar.php'; ?>
<?php if (file_exists('../header.php')) include '../header.php'; ?>

<div class="main-content">
<div class="container">

<!-- HEADER -->
<div class="page-header">
<i class="fa-solid fa-user-doctor"></i>
<div>
<h1>Doctor Management</h1>
<p>Add and manage doctor records</p>
</div>
</div>

<!-- MESSAGE -->
<?php if (isset($_GET['msg']) && $_GET['msg'] === 'added'): ?>
<div class="message">Doctor added successfully.</div>
<?php endif; ?>

<!-- FORM -->
<div class="card">
<form method="POST">

<div class="form-group">
<label>Doctor Name</label>
<input type="text" name="name" placeholder="Enter doctor name" required>
</div>

<div class="form-group">
<label>Mobile</label>
<input type="text" name="mobile" placeholder="Enter mobile number">
</div>

<div class="form-group">
<label>City</label>
<input type="text" name="city" placeholder="Enter city">
</div>

<div class="form-group">
<label>Specialization</label>
<input type="text" name="specialization" placeholder="Enter specialization">
</div>

<div class="btn-center">
<button type="submit" class="btn">
<i class="fa-solid fa-plus"></i> Add Doctor
</button>
</div>

</form>
</div>

</div>
</div>

</body>
</html>