<?php
include 'db.php';
session_start();
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Call Survey Dashboard</title>

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

<style>
  /* ===== Global Layout ===== */
body {
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(135deg, #1e3c72, #2a5298);
  margin: 0;
  padding: 0;
  color: #333;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ===== Main Container ===== */
.container {
  width: 70%;
  max-width: 1100px;
  background: #ffffff;
  margin: 60px auto;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  padding: 40px;
  animation: fadeIn 0.8s ease-in-out;
}

/* ===== Header ===== */
.header {
  text-align: center;
  margin-bottom: 40px;
}

.header h1 {
  font-size: 2.6em;
  font-weight: 700;
  color: #2a5298;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.header h1 i {
  color: #1e3c72;
  font-size: 1.6em;
}

/* ===== Form Styling ===== */
form {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

label {
  font-weight: 600;
  color: #444;
}

input[type="text"] {
  padding: 12px;
  width: 260px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.3s ease;
}

input[type="text"]:focus {
  border-color: #2a5298;
  box-shadow: 0 0 8px rgba(42, 82, 152, 0.4);
  outline: none;
}

button {
  background: linear-gradient(135deg, #1e3c72, #2a5298);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

button:hover {
  background: linear-gradient(135deg, #2a5298, #1e3c72);
  transform: translateY(-2px);
}

/* ===== Section Title ===== */
.section-title {
  text-align: center;
  font-size: 1.8em;
  font-weight: 700;
  color: #333;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.section-title i {
  color: #2a5298;
}

/* ===== Table Styling ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  border-radius: 8px;
  overflow: hidden;
}

thead tr {
  background: linear-gradient(135deg, #1e3c72, #2a5298);
}

th {
  color: #fff;
  padding: 14px;
  text-align: left;
  font-size: 15px;
  letter-spacing: 0.5px;
}

td {
  padding: 12px;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  color: #444;
}
td:hover {
  color: #ffffff;
  font-weight: 600;
}
tr:nth-child(even) {
  background-color: #f9f9ff;
}

tr:hover {
  background-color: #304c8e;
  transition: background 0.3s ease;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  margin-top: 40px;
  font-size: 13px;
  color: #666;
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

</style>


</head>
<body>
  <div class="container">
    <!-- Header -->
    <div class="header">
      <h1><i class="fas fa-phone"></i> Call Survey</h1>
    </div>

    <!-- Survey Form -->
    <form action="call.php" method="POST">
      <label for="phone_number">Enter Phone Number:</label>
      <input type="text" id="phone_number" name="phone_number" placeholder="+2547XXXXXXXX" required>
      <button type="submit"><i class="fas fa-play"></i> Start Survey</button>
    </form>

    <!-- Responses Section -->
    <div class="section-title">
      <i class="fas fa-chart-bar"></i> Collected Responses
    </div>

    <table>
      <thead>
        <tr>
          <th>Phone</th>
          <th>Rec1</th>
          <th>Rec2</th>
          <th>Timestamp</th>
        </tr>
      </thead>
      <tbody>
        <?php
        $res = $conn->query("SELECT * FROM surveys ORDER BY created_at DESC");
        while ($row = $res->fetch_assoc()) {
          echo "<tr>
                  <td>{$row['phone_number']}</td>
                  <td>{$row['rec1']}</td>
                  <td>{$row['rec2']}</td>
                  <td>{$row['created_at']}</td>
                </tr>";
        }
        ?>
      </tbody>
    </table>

    <!-- Footer -->
    <div class="footer">
      <p>© 2026 Webbyfix Technologies — Call Survey Dashboard</p>
    </div>
  </div>
</body>
</html>
