<?php include 'includes/header.php'; ?>
<?php include 'includes/db.php'; ?>

<?php
$id = intval($_GET['id']);
$news = $conn->query("SELECT * FROM news WHERE id=$id")->fetch_assoc();
$images = $conn->query("SELECT * FROM news_images WHERE news_id=$id");
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?= htmlspecialchars($news['title']) ?></title>

<style>
/* ===== Base ===== */
body {
  background: #f4f6f9;
  font-family: "Georgia", "Segoe UI", serif;
  margin: 0;
}

/* ===== Container ===== */
.news-details {
  width: 85%;
  max-width: 1200px;
  margin: 60px auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  padding: 40px;
  animation: fadeIn 0.8s ease;
}

/* ===== Title ===== */
.news-details h1 {
  font-size: 2.2rem;
  color: #25A9C2;
  margin-bottom: 8px;
  line-height: 1.3;
}

/* ===== Meta ===== */
.news-meta {
  font-size: 0.95rem;
  color: #777;
  margin-bottom: 30px;
  border-bottom: 1px solid #eee;
  padding-bottom: 12px;
}

/* ===== Layout ===== */
.news-layout {
  display: grid;
  grid-template-columns: 1.2fr 2fr;
  gap: 35px;
  align-items: start;
}

/* ===== Images ===== */
.news-images {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.news-images img {
  width: 100%;
  border-radius: 10px;
  object-fit: cover;
  animation: fadeUp 0.8s ease;
}

/* First image larger */
.news-images img:first-child {
  height: 360px;
}

/* Other images smaller */
.news-images img:not(:first-child) {
  height: 180px;
}

/* ===== Content ===== */
.news-content {
  font-size: 1.05rem;
  line-height: 1.9;
  color: #222;
  animation: fadeUp 1s ease;
}

.news-content p {
  margin-bottom: 18px;
}

/* Newspaper feel */
.news-content::first-letter {
  font-size: 3.5rem;
  font-weight: bold;
  float: left;
  line-height: 1;
  padding-right: 10px;
  color: #25A9C2;
}

/* ===== Back Button ===== */
.back-btn {
  display: inline-block;
  margin-top: 40px;
  background: #25A9C2;
  color: Black;
  padding: 12px 26px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  transition: 0.3s;
}

.back-btn:hover {
  background: #0d154d;
}

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

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(25px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .news-layout {
    grid-template-columns: 1fr;
  }

  .news-images img:first-child {
    height: 260px;
  }

  .news-images img:not(:first-child) {
    height: 160px;
  }
}
</style>
</head>

<body>

<div class="news-details">

  <h1><?= htmlspecialchars($news['title']) ?></h1>

  <div class="news-meta">
    🕒 <?= date('d M Y', strtotime($news['created_at'])) ?>
    &nbsp;•&nbsp;
    ✍️ <?= htmlspecialchars($news['author'] ?? 'Admin') ?>
  </div>

  <div class="news-layout">

    <!-- Images -->
    <div class="news-images">
      <?php while($img = $images->fetch_assoc()): ?>
        <img src="<?= htmlspecialchars($img['image_path']) ?>" alt="News Image">
      <?php endwhile; ?>
    </div>

    <!-- Content -->
    <div class="news-content">
      <?= $news['content'] ?>
    </div>

  </div>


</div>

<?php include 'includes/footer.php'; ?>
</body>
</html>
