<?php include 'header.php'; ?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Target — View</title>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/remixicon@4.2.0/fonts/remixicon.css" rel="stylesheet"/>
<script src="https://cdn.tailwindcss.com"></script>
<style>:root{--ink:#0f0e17;--muted:#6b6b80;--line:#e8e8f0;--accent:#5b4fcf;--accent-light:#ede9ff;--accent-mid:#8b7ee8;--surface:#fafafa;--white:#ffffff;--green:#16a34a;--green-light:#dcfce7;--amber:#d97706;--amber-light:#fef3c7;}*{box-sizing:border-box;margin:0;padding:0;}html,body{width:100%;overflow-x:hidden;}body{font-family:'DM Sans',sans-serif;background:var(--surface);color:var(--ink);min-height:100vh;-webkit-font-smoothing:antialiased;line-height:1.5;font-size:14px;}.topbar{background:var(--white);border-bottom:1px solid var(--line);padding:0 clamp(12px,2vw,28px);height:60px;display:flex;align-items:center;justify-content:space-between;position:sticky;top:0;z-index:100;}.topbar-brand{font-family:'Playfair Display',serif;font-size:19px;font-weight:700;color:var(--ink);letter-spacing:-0.2px;}.topbar-brand span{color:var(--accent);}.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:36px;padding:0 15px;border-radius:10px;font-size:12px;font-weight:600;cursor:pointer;transition:all .18s ease;border:none;text-decoration:none;white-space:nowrap;}.btn-ghost{background:transparent;border:1px solid var(--line);color:var(--muted);}.btn-ghost:hover{border-color:var(--accent-mid);background:var(--accent-light);color:var(--accent);}.btn-primary{background:var(--accent);color:#fff;box-shadow:0 4px 14px rgba(91,79,207,.22);}.btn-primary:hover{background:#4b40c5;}.btn-danger{background:#fff5f5;border:1px solid #fecaca;color:#dc2626;}.btn-danger:hover{background:#dc2626;color:#fff;}.page{max-width:1360px;width:100%;margin:0 auto;padding:clamp(12px,2vw,28px);}.hero{background:var(--white);border:1px solid var(--line);border-radius:22px;padding:clamp(20px,3vw,32px);margin-bottom:20px;position:relative;overflow:hidden;}.hero::before{content:'';position:absolute;top:0;left:0;right:0;height:5px;background:linear-gradient(90deg,var(--accent) 0%,var(--accent-mid) 60%,#c4b5fd 100%);}.hero-inner{display:flex;align-items:flex-start;justify-content:space-between;gap:24px;flex-wrap:wrap;}.avatar-wrap{position:relative;flex-shrink:0;}.avatar{width:clamp(80px,11vw,110px);height:clamp(80px,11vw,110px);border-radius:20px;border:3px solid var(--line);background:var(--accent-light);display:flex;align-items:center;justify-content:center;font-family:'Playfair Display',serif;font-size:clamp(28px,4vw,40px);font-weight:700;color:var(--accent);object-fit:cover;}.avatar-status{position:absolute;bottom:5px;right:5px;width:14px;height:14px;border-radius:50%;background:var(--green);border:2px solid var(--white);}.hero-info{flex:1;min-width:240px;}.hero-name{font-family:'Playfair Display',serif;font-size:clamp(24px,4vw,32px);font-weight:700;color:var(--ink);line-height:1.2;margin-bottom:4px;}.hero-designation{font-size:14px;color:var(--muted);margin-bottom:14px;}.hero-pills{display:flex;flex-wrap:wrap;gap:7px;margin-bottom:16px;}.pill{display:inline-flex;align-items:center;gap:5px;height:26px;padding:0 11px;border-radius:18px;font-size:11px;font-weight:600;white-space:nowrap;}.pill-accent{background:var(--accent-light);color:var(--accent);}.pill-green{background:var(--green-light);color:var(--green);}.pill-amber{background:var(--amber-light);color:var(--amber);}.pill-gray{background:#f3f4f6;color:#374151;}.hero-meta{display:flex;flex-wrap:wrap;gap:16px;}.hero-meta-item{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted);}.hero-meta-item i{font-size:14px;color:var(--accent-mid);}.hero-actions{display:flex;flex-direction:column;gap:8px;flex-shrink:0;}.tabs-wrap{background:var(--white);border:1px solid var(--line);border-radius:16px;margin-bottom:18px;overflow:hidden;}.tabs{display:flex;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch;padding:5px;gap:4px;}.tabs::-webkit-scrollbar{display:none;}.tab{display:inline-flex;align-items:center;gap:6px;padding:9px 16px;border-radius:10px;font-size:12px;font-weight:500;border:none;background:transparent;color:var(--muted);cursor:pointer;white-space:nowrap;transition:all .18s ease;flex-shrink:0;}.tab i{font-size:14px;}.tab.active{background:var(--accent-light);color:var(--accent);font-weight:600;}.tab:not(.active):hover{background:#f4f4f6;color:var(--ink);}.tab-content{display:none;}.tab-content.active{display:block;}.section-card{background:var(--white);border:1px solid var(--line);border-radius:18px;margin-bottom:18px;overflow:hidden;}.section-head{padding:16px 20px;border-bottom:1px solid var(--line);display:flex;align-items:center;gap:10px;}.section-head-icon{width:32px;height:32px;border-radius:9px;background:var(--accent-light);display:flex;align-items:center;justify-content:center;flex-shrink:0;}.section-head-icon i{font-size:16px;color:var(--accent);}.section-head-title{font-family:'Playfair Display',serif;font-size:15px;font-weight:600;color:var(--ink);}.section-body{padding:20px;}.field-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:18px 24px;}.field-grid.two-col{grid-template-columns:repeat(auto-fit,minmax(260px,1fr));}.field-group{min-width:0;}.field-label{font-size:10px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin-bottom:4px;display:flex;align-items:center;gap:4px;}.field-label i{font-size:11px;}.field-value{font-size:14px;font-weight:500;color:var(--ink);line-height:1.5;word-break:break-word;}.field-value.empty{color:#c7c9d1;font-style:italic;font-weight:400;}.divider{border:none;border-top:1px solid var(--line);margin:18px 0;}.sub-head{font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--accent);margin-bottom:14px;display:flex;align-items:center;gap:6px;}.sub-head::after{content:'';flex:1;height:1px;background:var(--accent-light);}.milestone-card{border:1px solid var(--line);border-radius:14px;padding:14px 16px;background:#faf5ff;display:flex;align-items:center;gap:14px;}.milestone-badge{width:36px;height:36px;border-radius:10px;background:var(--accent-light);display:flex;align-items:center;justify-content:center;flex-shrink:0;font-size:13px;font-weight:700;color:var(--accent);}.milestone-info{flex:1;}.milestone-label{font-size:10px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin-bottom:2px;}.milestone-val{font-size:15px;font-weight:600;color:var(--ink);}.milestone-bar-wrap{margin-top:6px;height:5px;background:var(--line);border-radius:10px;overflow:hidden;}.milestone-bar{height:100%;border-radius:10px;background:linear-gradient(90deg,var(--accent),var(--accent-mid));}.check-row{display:flex;align-items:center;gap:8px;padding:8px 0;}.check-icon{width:20px;height:20px;border-radius:5px;display:flex;align-items:center;justify-content:center;flex-shrink:0;}.check-icon.on{background:var(--green-light);}.check-icon.off{background:#f3f4f6;}.check-icon.on i{font-size:12px;color:var(--green);}.check-icon.off i{font-size:12px;color:#9ca3af;}.check-label{font-size:13px;color:var(--ink);}@media(max-width:1024px){.page{padding:14px;}.field-grid{grid-template-columns:repeat(auto-fit,minmax(200px,1fr));}}@media(max-width:768px){.page{padding:12px;}.hero{padding:18px;border-radius:18px;}.hero-inner{flex-direction:column;gap:18px;}.hero-actions{width:100%;flex-direction:row;flex-wrap:wrap;}.hero-actions .btn{flex:1;min-width:130px;}.field-grid{grid-template-columns:1fr 1fr;gap:14px 16px;}.section-body{padding:16px;}}@media(max-width:520px){.page{padding:10px;}.hero{padding:16px;border-radius:16px;}.hero-name{font-size:24px;}.hero-meta{flex-direction:column;gap:8px;}.field-grid{grid-template-columns:1fr;}.section-head{padding:14px 16px;}.section-body{padding:14px;}.hero-actions{flex-direction:column;width:100%;}.hero-actions .btn{width:100%;}.topbar{padding:0 10px;height:56px;}.tab{padding:8px 13px;font-size:11px;}}@media(max-width:380px){.avatar{width:72px;height:72px;font-size:26px;}.hero-name{font-size:22px;}}</style>
</head>
<body>

<div class="max-w-[1800px] mx-auto mt-6 mb-5 flex items-center justify-between gap-3">
  <h1 class="text-[18px] sm:text-2xl font-bold text-black leading-tight">
    View Target Details
  </h1>
</div>

<div class="page">

  <!-- HERO CARD -->
  <div class="hero">
    <div class="hero-inner">
      <div class="avatar-wrap">
        <div class="avatar"><i class="ri-focus-3-line" style="font-size:clamp(30px,5vw,44px);"></i></div>
        <div class="avatar-status"></div>
      </div>
      <div class="hero-info">
        <div class="hero-name"><?= htmlspecialchars($target['target_name']) ?></div>
        <div class="hero-designation"><?= htmlspecialchars($target['target_type']) ?> Target &nbsp;·&nbsp; <?= htmlspecialchars($target['team_user']) ?></div>
        <div class="hero-pills">
          <?php
            $statusClass = match($target['status']) {
              'Active'   => 'pill-green',
              'Inactive' => 'pill-gray',
              'Draft'    => 'pill-amber',
              default    => 'pill-gray',
            };
            $statusIcon = match($target['status']) {
              'Active'   => '<i class="ri-radio-button-fill" style="font-size:9px;"></i>',
              'Inactive' => '<i class="ri-pause-circle-line"></i>',
              'Draft'    => '<i class="ri-draft-line"></i>',
              default    => '',
            };
          ?>
          <span class="pill <?= $statusClass ?>"><?= $statusIcon ?> <?= htmlspecialchars($target['status']) ?></span>
          <span class="pill pill-accent"><i class="ri-calendar-check-line"></i> <?= htmlspecialchars($target['frequency']) ?></span>
          <span class="pill pill-gray"><i class="ri-team-line"></i> <?= htmlspecialchars($target['team_user']) ?></span>
          <span class="pill pill-amber"><i class="ri-trophy-line"></i> <?= htmlspecialchars($target['target_type']) ?></span>
        </div>
        <div class="hero-meta">
          <div class="hero-meta-item"><i class="ri-money-rupee-circle-line"></i> ₹ <?= number_format($target['target_amount']) ?> Target</div>
          <div class="hero-meta-item"><i class="ri-calendar-line"></i> <?= date('d M Y', strtotime($target['start_date'])) ?> – <?= date('d M Y', strtotime($target['end_date'])) ?></div>
          <?php if (!empty($target['incentive_value'])): ?>
          <div class="hero-meta-item"><i class="ri-gift-line"></i> Incentive: ₹ <?= number_format($target['incentive_value']) ?></div>
          <?php endif; ?>
        </div>
      </div>
      <div class="hero-actions">
        <a href="puresaas_target.php">
          <button class="btn btn-ghost" style="font-size:12px;">
            <i class="ri-arrow-left-line"></i> Back
          </button>
        </a>
        <button class="btn btn-ghost" style="font-size:12px;">
          <i class="ri-download-line"></i> Export
        </button>
        <button class="btn btn-danger" style="font-size:12px;">
          <i class="ri-delete-bin-line"></i> Delete
        </button>
      </div>
    </div>
  </div>

  <!-- TABS -->
  <div class="tabs-wrap">
    <div class="tabs">
      <button class="tab active" onclick="switchTab('details',this)"><i class="ri-flag-line"></i> Target Details</button>
      <button class="tab" onclick="switchTab('setting',this)"><i class="ri-settings-3-line"></i> Target Setting</button>
    </div>
  </div>

  <!-- ========================
       TAB 1 — TARGET DETAILS
  ========================= -->
  <div id="tab-details" class="tab-content active">
    <div class="section-card">
      <div class="section-head">
        <div class="section-head-icon"><i class="ri-flag-line"></i></div>
        <div class="section-head-title">Target Details</div>
      </div>
      <div class="section-body">

        <div class="sub-head"><i class="ri-profile-line"></i> Basic Information</div>
        <div class="field-grid">
          <div class="field-group">
            <div class="field-label">Target Name</div>
            <div class="field-value"><?= htmlspecialchars($target['target_name']) ?></div>
          </div>
          <div class="field-group">
            <div class="field-label">Target Type</div>
            <div class="field-value">
              <span class="pill pill-amber" style="font-size:13px;">
                <i class="ri-trophy-line"></i> <?= htmlspecialchars($target['target_type']) ?>
              </span>
            </div>
          </div>
          <div class="field-group">
            <div class="field-label">Team / User</div>
            <div class="field-value">
              <span class="pill pill-accent" style="font-size:13px;">
                <i class="ri-team-line"></i> <?= htmlspecialchars($target['team_user']) ?>
              </span>
            </div>
          </div>
          <div class="field-group">
            <div class="field-label">Target Amount</div>
            <div class="field-value" style="font-size:16px;font-weight:600;">₹ <?= number_format($target['target_amount']) ?></div>
          </div>
        </div>

        <hr class="divider"/>
        <div class="sub-head"><i class="ri-calendar-line"></i> Schedule</div>
        <div class="field-grid">
          <div class="field-group">
            <div class="field-label">Start Date</div>
            <div class="field-value"><?= date('d F Y', strtotime($target['start_date'])) ?></div>
          </div>
          <div class="field-group">
            <div class="field-label">End Date</div>
            <div class="field-value"><?= date('d F Y', strtotime($target['end_date'])) ?></div>
          </div>
        </div>

        <hr class="divider"/>
        <div class="sub-head"><i class="ri-file-text-line"></i> Description</div>
        <div class="field-group">
          <?php if (!empty($target['description'])): ?>
            <div class="field-value" style="background:#faf5ff;border:1px solid var(--line);border-radius:12px;padding:14px 16px;font-size:13px;line-height:1.7;">
              <?= nl2br(htmlspecialchars($target['description'])) ?>
            </div>
          <?php else: ?>
            <div class="field-value empty">No description provided.</div>
          <?php endif; ?>
        </div>

      </div>
    </div>
  </div>

  <!-- ========================
       TAB 2 — TARGET SETTING
  ========================= -->
  <div id="tab-setting" class="tab-content">
    <div class="section-card">
      <div class="section-head">
        <div class="section-head-icon"><i class="ri-settings-3-line"></i></div>
        <div class="section-head-title">Target Setting</div>
      </div>
      <div class="section-body">

        <div class="sub-head"><i class="ri-timer-line"></i> Frequency & Status</div>
        <div class="field-grid">
          <div class="field-group">
            <div class="field-label">Frequency</div>
            <div class="field-value">
              <span class="pill pill-accent" style="font-size:13px;">
                <i class="ri-calendar-check-line"></i> <?= htmlspecialchars($target['frequency']) ?>
              </span>
            </div>
          </div>
          <div class="field-group">
            <div class="field-label">Status</div>
            <div class="field-value">
              <span class="pill <?= $statusClass ?>" style="font-size:13px;">
                <?= $statusIcon ?> <?= htmlspecialchars($target['status']) ?>
              </span>
            </div>
          </div>
        </div>

        <hr class="divider"/>
        <div class="sub-head"><i class="ri-gift-line"></i> Incentive</div>
        <div class="field-grid">
          <div class="field-group">
            <div class="field-label">Incentive Type</div>
            <div class="field-value">
              <?= !empty($target['incentive_type']) ? htmlspecialchars($target['incentive_type']) : '<span class="empty">—</span>' ?>
            </div>
          </div>
          <div class="field-group">
            <div class="field-label">Incentive Value</div>
            <div class="field-value" style="font-size:16px;font-weight:600;">
              <?php if (!empty($target['incentive_value'])): ?>
                ₹ <?= number_format($target['incentive_value']) ?>
              <?php else: ?>
                <span class="empty">—</span>
              <?php endif; ?>
            </div>
          </div>
        </div>

        <hr class="divider"/>
        <div class="sub-head"><i class="ri-bar-chart-grouped-line"></i> Milestones</div>
        <div style="display:flex;flex-direction:column;gap:12px;">

          <?php
          $milestones = [
            ['label' => 'Milestone 1', 'badge' => 'M1', 'val' => $target['milestone1'] ?? null],
            ['label' => 'Milestone 2', 'badge' => 'M2', 'val' => $target['milestone2'] ?? null],
            ['label' => 'Milestone 3', 'badge' => 'M3', 'val' => $target['milestone3'] ?? null],
          ];
          foreach ($milestones as $ms):
            $pct = $ms['val'] ?? 0;
            $amt = ($pct / 100) * $target['target_amount'];
          ?>
          <div class="milestone-card">
            <div class="milestone-badge"><?= $ms['badge'] ?></div>
            <div class="milestone-info">
              <div class="milestone-label"><?= $ms['label'] ?></div>
              <?php if (!empty($ms['val'])): ?>
                <div class="milestone-val">
                  <?= $pct ?>% of target
                  <span style="color:var(--muted);font-size:12px;font-weight:400;">= ₹ <?= number_format($amt) ?></span>
                </div>
                <div class="milestone-bar-wrap">
                  <div class="milestone-bar" style="width:<?= $pct ?>%;"></div>
                </div>
              <?php else: ?>
                <div class="field-value empty">Not set</div>
              <?php endif; ?>
            </div>
          </div>
          <?php endforeach; ?>

        </div>

        <hr class="divider"/>
        <div class="sub-head"><i class="ri-checkbox-circle-line"></i> Settings</div>
        <div style="display:flex;flex-direction:column;gap:4px;">

          <div class="check-row">
            <div class="check-icon <?= !empty($target['notify_on_milestone']) ? 'on' : 'off' ?>">
              <i class="<?= !empty($target['notify_on_milestone']) ? 'ri-check-line' : 'ri-close-line' ?>"></i>
            </div>
            <span class="check-label" style="<?= empty($target['notify_on_milestone']) ? 'color:var(--muted);' : '' ?>">
              Notify team on milestone achievement
            </span>
          </div>

          <div class="check-row">
            <div class="check-icon <?= !empty($target['auto_reset']) ? 'on' : 'off' ?>">
              <i class="<?= !empty($target['auto_reset']) ? 'ri-check-line' : 'ri-close-line' ?>"></i>
            </div>
            <span class="check-label" style="<?= empty($target['auto_reset']) ? 'color:var(--muted);' : '' ?>">
              Auto-reset target on period end
            </span>
          </div>

        </div>

      </div>
    </div>
  </div>

</div><!-- /page -->

<script>
function switchTab(name, el) {
  document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
  document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  document.getElementById('tab-' + name).classList.add('active');
  el.classList.add('active');
}
</script>
</body>
</html>

<?php include 'footer.php'; ?>