<?php
require_once __DIR__ . '/career/includes/db.php';
require_once __DIR__ . '/career/includes/functions.php';
$pdo = get_db();
$jobs = $pdo->query("SELECT * FROM jobs WHERE status = 'published' ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Careers — Delmas Apparels (Pvt.) Limited</title>
  <meta name="description" content="Current job openings at Delmas Apparels (Pvt.) Limited, CEPZ, Chattogram.">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
  <link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400&family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
  <link rel="stylesheet" href="style.css" />
  <style>
    /* Delmas Apparels brand palette (matches index.html) */
    :root{
      --gold:#C9A84C; --gold-light:#E8C96A; --gold-dark:#8B6914;
      --bg-dark:#0A0A0A; --bg-light:#F5F0E8;
      --text-white:#FAFAF8; --text-dark:#0A0A0A; --text-muted:#8A8A8A; --text-body:#333;
      --border-gold:rgba(201,168,76,.25);
      --transition:all .3s ease;
      --fd:'Cormorant Garamond',serif; --fb:'Outfit',sans-serif;
    }
    body{font-family:var(--fb)}
    #mainNav{font-family:var(--fb)}
    .brand-main{font-family:var(--fd);font-weight:600;letter-spacing:.04em;color:var(--text-white)}
    .brand-accent{font-family:var(--fd);font-weight:300;letter-spacing:.04em;color:var(--gold-light)}
    .toggler-line{display:block;width:22px;height:2px;background:var(--gold);margin:4px 0}
    #mainNav .nav-link{color:var(--text-white);opacity:.85;font-size:.8rem;letter-spacing:.05em;text-transform:uppercase}
    #mainNav .nav-link:hover{color:var(--gold-light)!important;opacity:1}
    .nav-cta{border:1px solid var(--gold);border-radius:3px;padding:.4rem 1rem!important}
    .btn-primary-tapl{display:inline-block;background:var(--gold);color:var(--bg-dark);border:1px solid var(--gold);padding:.65rem 1.6rem;font-family:var(--fb);font-weight:600;font-size:.82rem;letter-spacing:.06em;text-transform:uppercase;border-radius:3px;transition:var(--transition);text-decoration:none}
    .btn-primary-tapl:hover{background:transparent;color:var(--gold)}
    .section-label-light{display:inline-block;color:var(--gold-light);font-size:.78rem;letter-spacing:.15em;text-transform:uppercase;font-weight:600;margin-bottom:.6rem}
    .career-hero{background:var(--bg-dark);padding:9rem 0 4rem;text-align:center}
    .career-hero h1{font-family:var(--fd);color:var(--text-white);font-size:clamp(2.2rem,5vw,3.2rem)}
    .career-hero p{color:var(--text-muted);max-width:600px;margin:1rem auto 0}
    .career-list{padding:4rem 0;background:var(--bg-light)}
    .job-card{background:#fff;border:1px solid var(--border-gold);border-radius:6px;padding:1.8rem;margin-bottom:1.3rem;transition:var(--transition)}
    .job-card:hover{box-shadow:0 10px 30px rgba(0,0,0,.08);transform:translateY(-2px)}
    .job-title{font-family:var(--fd);font-size:1.5rem;color:var(--text-dark);font-weight:600}
    .job-meta{font-size:.82rem;color:var(--text-muted);letter-spacing:.03em;margin:.4rem 0 .8rem}
    .job-meta span{margin-right:1.1rem}
    .job-badge-closed{display:inline-block;font-size:.7rem;letter-spacing:.1em;text-transform:uppercase;color:#9e3d3d;background:#fbe9e9;padding:.25rem .6rem;border-radius:3px}
    .job-badge-open{display:inline-block;font-size:.7rem;letter-spacing:.1em;text-transform:uppercase;color:#1e7a46;background:#e8f6ee;padding:.25rem .6rem;border-radius:3px}
    .no-jobs{text-align:center;color:var(--text-muted);padding:3rem 0}
  </style>
</head>
<body>

  <!-- NAVBAR (matches main site) -->
  <nav class="navbar navbar-expand-lg fixed-top" id="mainNav" style="background:rgba(7,13,26,.97);backdrop-filter:blur(12px)">
    <div class="container">
      <a class="navbar-brand" href="index.html"><span class="brand-main">DELMAS</span> <span class="brand-accent">APPARELS</span></a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
        <span class="toggler-line"></span><span class="toggler-line"></span><span class="toggler-line"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ms-auto">
          <li class="nav-item"><a class="nav-link" href="index.html#home">Home</a></li>
          <li class="nav-item"><a class="nav-link" href="index.html#about">About</a></li>
          <li class="nav-item"><a class="nav-link" href="index.html#our-story">Story</a></li>
          <li class="nav-item"><a class="nav-link" href="index.html#works">Works</a></li>
          <li class="nav-item"><a class="nav-link" href="career.php" style="color:var(--gold)!important">Career</a></li>
          <li class="nav-item"><a class="nav-link" href="career/admin/login.php"><i class="fas fa-user-lock me-1" style="font-size:.8rem"></i>Admin Login</a></li>
          <li class="nav-item"><a class="nav-link nav-cta" href="index.html#contact">Get In Touch</a></li>
        </ul>
      </div>
    </div>
  </nav>

  <section class="career-hero">
    <div class="container">
      <span class="section-label-light">Join Our Team</span>
      <h1>Careers at <em style="color:var(--gold-light)">Delmas Apparels</em></h1>
      <p>Explore current opportunities at Delmas Apparels (Pvt.) Limited and apply directly online.</p>
    </div>
  </section>

  <section class="career-list">
    <div class="container" style="max-width:820px">
      <?php if (!$jobs): ?>
        <div class="no-jobs">
          <i class="fas fa-briefcase fa-2x mb-3" style="color:var(--gold)"></i>
          <p>There are no open positions right now. Please check back soon.</p>
        </div>
      <?php else: foreach ($jobs as $job):
          $expired = is_job_expired($job['deadline']);
      ?>
        <div class="job-card">
          <div class="d-flex justify-content-between align-items-start flex-wrap gap-2">
            <div class="job-title"><?= h($job['title']) ?></div>
            <?php if ($expired): ?>
              <span class="job-badge-closed">Closed</span>
            <?php else: ?>
              <span class="job-badge-open">Open</span>
            <?php endif; ?>
          </div>
          <div class="job-meta">
            <?php if ($job['department']): ?><span><i class="fas fa-layer-group"></i> <?= h($job['department']) ?></span><?php endif; ?>
            <?php if ($job['location']): ?><span><i class="fas fa-location-dot"></i> <?= h($job['location']) ?></span><?php endif; ?>
            <?php if ($job['job_type']): ?><span><i class="fas fa-clock"></i> <?= h($job['job_type']) ?></span><?php endif; ?>
            <?php if ($job['salary']): ?><span><i class="fas fa-sack-dollar"></i> <?= h($job['salary']) ?></span><?php endif; ?>
            <?php if ($job['deadline']): ?><span><i class="fas fa-calendar"></i> Apply by <?= format_date_pretty($job['deadline']) ?></span><?php endif; ?>
          </div>
          <p class="mb-3" style="color:var(--text-body);font-size:.93rem">
            <?= h(truncate_text($job['description'])) ?>
          </p>
          <a href="job.php?id=<?= (int)$job['id'] ?>" class="btn-primary-tapl">View &amp; Apply</a>
        </div>
      <?php endforeach; endif; ?>
    </div>
  </section>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  <script>document.addEventListener('contextmenu', e => e.preventDefault());</script>
</body>
</html>
