<?php
// pricing.php — editorial minimalist redesign (public)
session_start();
include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/db.php');

$user_id     = (int)($_SESSION['user_id'] ?? 0);
$userPricing = '';

if ($user_id && isset($conn) && $conn instanceof mysqli) {
    $stmt = $conn->prepare("SELECT pricing_plan FROM users WHERE id=? LIMIT 1");
    $stmt->bind_param("i", $user_id); $stmt->execute();
    $res = $stmt->get_result()->fetch_assoc();
    if (!empty($res['pricing_plan'])) $userPricing = strtolower(trim($res['pricing_plan']));
    $stmt->close();
}

// ── DB'dan tarif narxlari/xususiyatlari/limitlari (admin /admin/tariffs.php boshqaradi) ──
$db_plans = [];
if (isset($conn) && $conn instanceof mysqli) {
    $rs = $conn->query("SELECT slug, name, price, duration_months, merchant_limit, monthly_tx_limit, is_active, features FROM pricing_plans WHERE slug IN ('standard','premium','business') ORDER BY FIELD(slug,'standard','premium','business')");
    if ($rs) while ($x = $rs->fetch_assoc()) $db_plans[$x['slug']] = $x;
}

// ── BYOK tariflari (admin /admin/byok_pricing.php boshqaradi) ──
$byok_plans = [];
if (isset($conn) && $conn instanceof mysqli) {
    $rs = $conn->query("SELECT id, slug, name, description, byok_tx_quota, byok_price_month, duration_months, color, features, is_active
                          FROM pricing_plans
                         WHERE mode='byok' AND is_active=1
                         ORDER BY byok_tx_quota ASC, sort_order ASC");
    if ($rs) while ($x = $rs->fetch_assoc()) $byok_plans[] = $x;
}

// Limit displeyi: NULL = "Cheksiz"
function pp_lim($v) {
    if ($v === null || $v === '') return 'Cheksiz';
    return number_format((int)$v, 0, '.', ' ') . ' ta';
}

function pp_fmt_price($p) {
    $p = (float)$p;
    if ($p <= 0) return '0';
    return number_format($p, 0, '.', ' ');
}
function pp_fmt_unit($months) {
    $m = max(1, (int)$months);
    if ($m === 1)  return '/oy';
    if ($m === 12) return '/yil';
    return '/' . $m . ' oy';
}
function pp_price_cell($plan) {
    if (!$plan) return '—';
    $price = (float)$plan['price'];
    if ($price <= 0) return "0 so'm";
    return pp_fmt_price($price) . " so'm" . pp_fmt_unit($plan['duration_months']);
}

function plan_button($plan, $current) {
    $p = strtolower($plan); $c = strtolower($current);
    if ($current === '') {
        return '<a href="/login/" class="pp-btn pp-btn-primary"><i class="bi bi-box-arrow-in-right"></i> Tanlash uchun kiring</a>';
    }
    if ($p === 'standard' && $c !== 'standard')
        return '<button class="pp-btn pp-btn-disabled" disabled><i class="bi bi-arrow-down"></i> Pastga o\'tib bo\'lmaydi</button>';
    if ($p === $c)
        return '<button class="pp-btn pp-btn-current" disabled><i class="bi bi-check-circle-fill"></i> Joriy tarif</button>';
    if ($p === 'business' && $c === 'business')
        return '<button class="pp-btn pp-btn-disabled" disabled>Barcha imkoniyatlar ochilgan</button>';
    $href = "https://" . $_SERVER['HTTP_HOST'] . '/billing/checkout?plan=' . urlencode($p);
    return '<a href="'.$href.'" class="pp-btn pp-btn-primary"><i class="bi bi-arrow-up-circle"></i> Darajaga o\'tkazish</a>';
}

function plan_active($plan, $current) { return strtolower($plan) === strtolower($current) ? 'current' : ''; }

include_once($_SERVER["DOCUMENT_ROOT"] . '/business/includes/head.php');
?>
<style>
.pp-page { background: var(--bg); min-height: 100vh; }
.pp-wrap { max-width: 1180px; margin: 0 auto; padding: 56px 24px 96px; }

/* Header */
.pp-head {
  text-align: center; margin-bottom: 48px;
  animation: ppUp .4s ease;
}
.pp-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: .72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .1em; margin-bottom: 18px;
}
.pp-eyebrow i { color: var(--accent); font-size: 12px; }
.pp-head h1 {
  font-family: var(--font-display); font-size: 2.6rem; font-weight: 700;
  letter-spacing: -.04em; color: var(--text); line-height: 1.05;
  max-width: 720px; margin: 0 auto 14px;
}
.pp-head h1 em { font-style: normal; color: var(--accent); font-weight: 700; }
.pp-head p {
  font-size: 1rem; color: var(--text-muted); line-height: 1.55;
  max-width: 540px; margin: 0 auto 24px;
}
.pp-current-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 100px;
  background: var(--accent-bg); border: 1px solid var(--accent-line);
  font-size: .82rem; font-weight: 600; color: var(--accent-strong);
}
.pp-current-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.pp-current-badge strong { font-family: var(--font-display); letter-spacing: .03em; }

/* Alert */
.pp-alert {
  background: var(--accent-bg); border: 1px solid var(--accent-line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-lg); padding: 14px 18px;
  font-size: .88rem; color: var(--accent-strong); margin-bottom: 28px;
  display: flex; align-items: center; gap: 10px;
}
.pp-alert i { font-size: 18px; }

/* Grid */
.pp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 64px; }

.pp-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-xl); padding: 32px 28px;
  display: flex; flex-direction: column;
  transition: border-color .2s, transform .2s, box-shadow .2s;
  position: relative; animation: ppUp .45s ease backwards;
}
.pp-card:nth-child(1) { animation-delay: .05s; }
.pp-card:nth-child(2) { animation-delay: .1s; }
.pp-card:nth-child(3) { animation-delay: .15s; }
.pp-card:hover { border-color: var(--line-2); transform: translateY(-3px); box-shadow: var(--shadow-2); }

.pp-card.featured {
  background: var(--accent-bg);
  border-color: var(--accent-line);
}
.pp-card.featured:hover { border-color: var(--accent); }

.pp-card.current {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}

.pp-badge-top {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  padding: 5px 12px; border-radius: 100px;
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; line-height: 1;
}
.pp-badge-top.featured { background: var(--text); color: var(--bg); }
.pp-badge-top.current  { background: var(--accent); color: #fff; display: inline-flex; align-items: center; gap: 5px; }

.pp-tag {
  display: inline-block; font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .12em; color: var(--text-soft);
  margin-bottom: 10px;
}
.pp-name {
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 700;
  letter-spacing: -.025em; color: var(--text); margin-bottom: 8px;
}
.pp-desc {
  font-size: .82rem; color: var(--text-muted); line-height: 1.5;
  margin-bottom: 20px; min-height: 36px;
}

.pp-price {
  font-family: var(--font-display); font-size: 2rem; font-weight: 700;
  color: var(--text); letter-spacing: -.03em;
  display: flex; align-items: baseline; gap: 6px;
  padding-bottom: 20px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.pp-card.featured .pp-price { border-color: var(--accent-line); }
.pp-price .pp-price-cur { font-size: .9rem; font-weight: 500; color: var(--text-muted); font-family: var(--font-body); letter-spacing: 0; }
.pp-price .pp-price-unit { font-size: .82rem; font-weight: 500; color: var(--text-soft); font-family: var(--font-body); letter-spacing: 0; }
.pp-price.free { color: var(--accent-strong); }

.pp-features { list-style: none; padding: 0; margin: 0 0 24px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.pp-features li {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: .88rem; line-height: 1.5;
}
.pp-features li.on  { color: var(--text); }
.pp-features li.off { color: var(--text-soft); text-decoration: line-through; text-decoration-color: var(--line-2); }
.pp-features li i { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.pp-features li.on i  { color: var(--accent); }
.pp-features li.off i { color: var(--line-2); }

/* Buttons */
.pp-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; border-radius: var(--radius);
  padding: 12px 20px; font-size: .88rem; font-weight: 600;
  border: 1px solid; cursor: pointer; font-family: var(--font-body);
  transition: opacity .15s, transform .12s, background .15s, color .15s;
}
.pp-btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.pp-btn-primary:hover { opacity: .88; color: var(--bg); }
.pp-btn-primary:active { transform: translateY(1px); }
.pp-card.featured .pp-btn-primary { background: var(--accent); border-color: var(--accent); }
.pp-card.featured .pp-btn-primary:hover { opacity: .9; }

.pp-btn-current {
  background: var(--accent-bg); color: var(--accent-strong);
  border-color: var(--accent-line); cursor: default;
}
.pp-btn-disabled {
  background: var(--surface-2); color: var(--text-soft);
  border-color: var(--line); cursor: not-allowed; opacity: .8;
}

/* BYOK section */
.pp-byok-divider {
  display: flex; align-items: center; gap: 18px;
  margin: 0 auto 28px; max-width: 720px;
}
.pp-byok-divider .line { flex: 1; height: 1px; background: var(--line); }
.pp-byok-divider .lbl {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 100px;
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857;
  font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.pp-byok-divider .lbl i { font-size: 12px; }
.pp-byok-intro { text-align: center; max-width: 640px; margin: 0 auto 32px; }
.pp-byok-intro h2 {
  font-family: var(--font-display); font-size: 1.75rem; font-weight: 700;
  letter-spacing: -.03em; color: var(--text); margin-bottom: 10px;
}
.pp-byok-intro p { font-size: .92rem; color: var(--text-muted); line-height: 1.6; }
.pp-byok-intro b { color: #047857; font-weight: 700; }
.pp-byok-grid { margin-bottom: 24px; }
.pp-byok-card { position: relative; }
.pp-byok-quota {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 100px;
  background: #ecfdf5; border: 1px solid #a7f3d0;
  font-size: .82rem; font-weight: 600; margin: 12px 0 18px;
}
.pp-byok-note {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px;
  padding: 14px 18px; margin-bottom: 56px;
  display: flex; gap: 10px; align-items: flex-start;
  font-size: .85rem; color: #1e3a8a; line-height: 1.55;
}
.pp-byok-note i { color: #1d4ed8; font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.pp-byok-note a { color: #1d4ed8; font-weight: 600; text-decoration: underline; }

/* Comparison table */
.pp-section-title {
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 700;
  letter-spacing: -.025em; color: var(--text); margin-bottom: 6px;
}
.pp-section-sub {
  font-size: .9rem; color: var(--text-muted); margin-bottom: 24px;
}

.pp-table-wrap {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-xl); overflow: hidden;
  margin-bottom: 64px; animation: ppUp .5s ease .15s backwards;
}
table.pp-cmp { width: 100%; border-collapse: collapse; }
table.pp-cmp thead { background: var(--surface-2); }
table.pp-cmp th {
  padding: 16px 20px; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text); text-align: center;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-display);
}
table.pp-cmp th:first-child {
  text-align: left; color: var(--text-soft); font-weight: 600;
}
table.pp-cmp td {
  padding: 14px 20px; font-size: .9rem;
  border-bottom: 1px solid var(--line); text-align: center;
  color: var(--text-muted);
}
table.pp-cmp td:first-child {
  text-align: left; font-weight: 600; color: var(--text);
}
table.pp-cmp tbody tr:hover { background: var(--surface-2); }
table.pp-cmp tbody tr:last-child td { border-bottom: none; }
table.pp-cmp i.bi-check-circle-fill { color: var(--accent); font-size: 18px; }
table.pp-cmp i.bi-x { color: var(--line-2); font-size: 20px; }

/* CTA */
.pp-cta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 32px; flex-wrap: wrap;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-xl); padding: 36px 40px;
  position: relative; overflow: hidden;
  animation: ppUp .5s ease .25s backwards;
}
.pp-cta-text { min-width: 0; flex: 1; }
.pp-cta-eyebrow {
  font-size: .72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: rgba(255,255,255,.55); margin-bottom: 8px;
}
.pp-cta h4 {
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 700;
  letter-spacing: -.025em; color: #fff; line-height: 1.15; margin-bottom: 6px;
}
.pp-cta p { font-size: .92rem; color: rgba(255,255,255,.65); line-height: 1.5; }
.pp-cta-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.pp-cta-outline,
.pp-cta-fill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 100px;
  font-size: .88rem; font-weight: 600; text-decoration: none;
  transition: all .15s; border: 1px solid;
}
.pp-cta-outline { background: transparent; color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.2); }
.pp-cta-outline:hover { background: rgba(255,255,255,.08); color: #fff; }
.pp-cta-fill { background: #fff; color: var(--text); border-color: #fff; }
.pp-cta-fill:hover { opacity: .9; color: var(--text); }

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

@media (max-width: 920px) {
  .pp-grid { grid-template-columns: 1fr; }
  .pp-head h1 { font-size: 2rem; }
  .pp-section-title { font-size: 1.3rem; }
  .pp-cta { padding: 28px 24px; }
  .pp-cta h4 { font-size: 1.25rem; }
  table.pp-cmp { font-size: .82rem; }
  table.pp-cmp th, table.pp-cmp td { padding: 12px 14px; }
}
@media (max-width: 600px) {
  .pp-wrap { padding: 36px 16px 80px; }
  .pp-head h1 { font-size: 1.7rem; }
  .pp-card { padding: 26px 22px; }
  .pp-cta { flex-direction: column; align-items: stretch; text-align: center; }
  .pp-cta-btns { flex-direction: column; }
  .pp-cta-outline, .pp-cta-fill { justify-content: center; }
}
</style>

<body class="pp-page">
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/business/includes/nav.php'); ?>

<div class="pp-wrap">

  <div class="pp-head">
    <div class="pp-eyebrow"><i class="bi bi-stars"></i> Tariflar</div>
    <h1>Mos tarifni tanlang va <em>boshlang</em></h1>
    <p>Standart tarif bepul. Biznes o'sgani sari Premium yoki Business'ga o'ting — limitlar va imkoniyatlar to'g'ridan-to'g'ri ochiladi.</p>
    <?php if ($userPricing !== ''): ?>
      <div class="pp-current-badge">
        <span class="dot"></span>
        Joriy darajangiz: <strong><?= strtoupper($userPricing) ?></strong>
      </div>
    <?php endif; ?>
  </div>

  <?php if (isset($_SESSION['message'])): ?>
    <div class="pp-alert">
      <i class="bi bi-info-circle-fill"></i>
      <span><?= htmlspecialchars($_SESSION['message']); unset($_SESSION['message']); ?></span>
    </div>
  <?php endif; ?>

  <div class="pp-grid">
    <?php
    // Statik dizayn meta-ma'lumotlari (tag/desc/zaxira xususiyatlar).
    // Narx, davomiylik, faollik va xususiyatlar ro'yxati — DB'dan keladi (admin /admin/tariffs.php).
    $plans = [
      'standard' => [
        'tag'   => "Boshlang'ich",
        'name'  => 'Standart',
        'desc'  => 'Birinchi qadamlar va kichik loyihalar uchun.',
        'feats' => [
          ['on'=>true,  'text'=>'1 ta kassa'],
          ['on'=>true,  'text'=>'Asosiy tranzaksiyalar'],
          ['on'=>true,  'text'=>'Hisob-kitob va kvitansiyalar'],
          ['on'=>false, 'text'=>'Kengaytirilgan analitika'],
          ['on'=>false, 'text'=>'Ustuvor qo\'llab-quvvatlash'],
        ]
      ],
      'premium' => [
        'tag'      => 'Kengaytirilgan',
        'name'     => 'Premium',
        'desc'     => "O'sayotgan biznes uchun keng imkoniyatlar.",
        'featured' => true,
        'feats' => [
          ['on'=>true,  'text'=>'5 ta kassa'],
          ['on'=>true,  'text'=>'Standart imkoniyatlari'],
          ['on'=>true,  'text'=>'Kengaytirilgan analitika'],
          ['on'=>true,  'text'=>'Ustuvor qo\'llab-quvvatlash'],
          ['on'=>false, 'text'=>'50 ta kassa va CARDSYSTEM'],
        ]
      ],
      'business' => [
        'tag'   => 'Maksimal',
        'name'  => 'Business',
        'desc'  => 'Yirik korxona va integratsiya uchun.',
        'feats' => [
          ['on'=>true, 'text'=>'Cheksiz kassa'],
          ['on'=>true, 'text'=>'Cheksiz oylik tranzaksiya'],
          ['on'=>true, 'text'=>'Premium imkoniyatlari'],
          ['on'=>true, 'text'=>'API + Webhook + CARDSYSTEM'],
          ['on'=>true, 'text'=>'SLA 99.9% kafolati'],
          ['on'=>true, 'text'=>'Alohida menejer'],
        ]
      ],
    ];
    foreach ($plans as $key => $plan):
      $db = $db_plans[$key] ?? null;
      // Admin o'chirib qo'ygan tarif foydalanuvchiga ko'rsatilmaydi
      if ($db && (int)$db['is_active'] !== 1) continue;

      $price_num = $db ? (float)$db['price'] : 0;
      $price_str = pp_fmt_price($price_num);
      $unit_str  = ($price_num > 0 && $db) ? pp_fmt_unit($db['duration_months']) : '';

      // Xususiyatlar: agar admin DB'da to'ldirgan bo'lsa — DB'dan, aks holda statik on/off ro'yxat
      $db_feats = [];
      if ($db && !empty($db['features'])) {
          $decoded = json_decode($db['features'], true);
          if (is_array($decoded)) $db_feats = $decoded;
      }

      $isActive   = plan_active($key, $userPricing) === 'current';
      $isFeatured = !empty($plan['featured']) && !$isActive;
    ?>
      <div class="pp-card <?= $isFeatured?'featured':'' ?> <?= $isActive?'current':'' ?>">
        <?php if ($isActive): ?>
          <div class="pp-badge-top current"><i class="bi bi-check-lg"></i> Joriy tarif</div>
        <?php elseif ($isFeatured): ?>
          <div class="pp-badge-top featured">Eng mashhur</div>
        <?php endif; ?>

        <div class="pp-tag"><?= $plan['tag'] ?></div>
        <div class="pp-name"><?= $plan['name'] ?></div>
        <div class="pp-desc"><?= htmlspecialchars($plan['desc']) ?></div>

        <div class="pp-price <?= $price_num <= 0 ? 'free' : '' ?>">
          <span><?= $price_str ?></span>
          <span class="pp-price-cur">so'm</span>
          <?php if ($unit_str !== ''): ?><span class="pp-price-unit"><?= $unit_str ?></span><?php endif; ?>
        </div>

        <ul class="pp-features">
          <?php if ($db_feats): ?>
            <?php foreach ($db_feats as $line): $line = (string)$line; if ($line === '') continue; ?>
              <li class="on">
                <i class="bi bi-check-circle-fill"></i>
                <span><?= htmlspecialchars($line) ?></span>
              </li>
            <?php endforeach; ?>
          <?php else: ?>
            <?php foreach ($plan['feats'] as $f): ?>
              <li class="<?= $f['on']?'on':'off' ?>">
                <i class="bi <?= $f['on']?'bi-check-circle-fill':'bi-dash-circle' ?>"></i>
                <span><?= htmlspecialchars($f['text']) ?></span>
              </li>
            <?php endforeach; ?>
          <?php endif; ?>
        </ul>

        <?= plan_button($key, $userPricing) ?>
      </div>
    <?php endforeach; ?>
  </div>

  <!-- ── BYOK SECTION ── -->
  <?php if (!empty($byok_plans)): ?>
  <div class="pp-byok-divider">
    <span class="line"></span>
    <span class="lbl"><i class="bi bi-shield-check"></i> BYOK — O'z Click/Payme kalitlaringiz orqali</span>
    <span class="line"></span>
  </div>
  <div class="pp-byok-intro">
    <h2>O'z biznesingiz, o'z hisobingiz</h2>
    <p>Pul to'g'ridan-to'g'ri sizning Click/Payme hisobingizdan o'tib bank hisobingizga tushadi.
    inPAY hech qachon mablag'ingizni ushlab turmaydi — faqat tranzaksiya statuslarini va statistikani ko'rsatadi.
    <b>Foiz YO'Q</b> — oddiy oylik obuna.</p>
  </div>
  <div class="pp-grid pp-byok-grid">
    <?php foreach ($byok_plans as $bp):
      $feats = [];
      if (!empty($bp['features'])) {
          $d = json_decode($bp['features'], true);
          if (is_array($d)) $feats = $d;
      }
      $color = $bp['color'] ?: '#10b981';
      $is_recommended = ($bp['slug'] === 'byok_pro');
    ?>
      <div class="pp-card pp-byok-card <?= $is_recommended ? 'featured' : '' ?>" style="border-top:4px solid <?= htmlspecialchars($color) ?>">
        <?php if ($is_recommended): ?>
          <div class="pp-badge-top featured" style="background:<?= htmlspecialchars($color) ?>">Eng mashhur</div>
        <?php endif; ?>
        <div class="pp-tag" style="color:<?= htmlspecialchars($color) ?>"><i class="bi bi-shield-check"></i> BYOK</div>
        <div class="pp-name"><?= htmlspecialchars($bp['name']) ?></div>
        <div class="pp-desc"><?= htmlspecialchars($bp['description'] ?: '') ?></div>

        <div class="pp-price">
          <span><?= pp_fmt_price($bp['byok_price_month']) ?></span>
          <span class="pp-price-cur">so'm</span>
          <span class="pp-price-unit"><?= pp_fmt_unit($bp['duration_months']) ?></span>
        </div>
        <div class="pp-byok-quota" style="color:<?= htmlspecialchars($color) ?>;">
          <i class="bi bi-lightning-charge-fill"></i>
          <?= $bp['byok_tx_quota'] ? number_format((int)$bp['byok_tx_quota']) . ' tranzaksiya' : 'Cheksiz tranzaksiya' ?>
          / <?= (int)$bp['duration_months'] ?> oy
        </div>

        <ul class="pp-features">
          <?php foreach ($feats as $f): if ($f === '') continue; ?>
            <li class="on"><i class="bi bi-check-circle-fill" style="color:<?= htmlspecialchars($color) ?>"></i> <span><?= htmlspecialchars($f) ?></span></li>
          <?php endforeach; ?>
        </ul>

        <?php if ($userPricing === ''): ?>
          <a href="/login/" class="pp-btn pp-btn-primary"><i class="bi bi-box-arrow-in-right"></i> Tanlash uchun kiring</a>
        <?php else: ?>
          <a href="/billing/byok-buy/?plan=<?= urlencode($bp['slug']) ?>" class="pp-btn pp-btn-primary" style="background:<?= htmlspecialchars($color) ?>;border-color:<?= htmlspecialchars($color) ?>"><i class="bi bi-shield-check"></i> Tanlash</a>
        <?php endif; ?>
      </div>
    <?php endforeach; ?>
  </div>
  <div class="pp-byok-note">
    <i class="bi bi-info-circle-fill"></i>
    <span><b>Eslatma:</b> BYOK tarif faqat <a href="/merchant/create">BYOK rejimida yaratilgan kassalar</a> uchun. Avval kassani BYOK rejimida yarating va Click/Payme kalitlaringizni kiriting.</span>
  </div>
  <?php endif; ?>

  <!-- Comparison -->
  <div class="pp-section-title">Taqqoslash</div>
  <div class="pp-section-sub">Har bir imkoniyat tariflarda qanday taqdim etilishi.</div>
  <div class="pp-table-wrap">
    <table class="pp-cmp">
      <thead>
        <tr>
          <th>Imkoniyat</th>
          <th>Standart</th>
          <th>Premium</th>
          <th>Business</th>
        </tr>
      </thead>
      <tbody>
        <?php
        $tx_s = $db_plans['standard']['monthly_tx_limit'] ?? 100;
        $tx_p = $db_plans['premium']['monthly_tx_limit']  ?? 1000;
        $tx_b = $db_plans['business']['monthly_tx_limit'] ?? null;
        $m_s  = $db_plans['standard']['merchant_limit']   ?? 1;
        $m_p  = $db_plans['premium']['merchant_limit']    ?? 5;
        $m_b  = $db_plans['business']['merchant_limit']   ?? null;

        $rows = [
          ['Narxi',
            pp_price_cell($db_plans['standard'] ?? null),
            pp_price_cell($db_plans['premium']  ?? null),
            pp_price_cell($db_plans['business'] ?? null)],
          ['Oylik tranzaksiya limiti',
            pp_lim($tx_s), pp_lim($tx_p), pp_lim($tx_b)],
          ['Kassalar soni',
            pp_lim($m_s),  pp_lim($m_p),  pp_lim($m_b)],
          ['Analitika paneli',   'icon:x',          'icon:ok',         'icon:ok'],
          ['API va Webhook',     'icon:ok',         'icon:ok',         'icon:ok'],
          ["Qo'llab-quvvatlash", 'Standart',        'Ustuvor',         '24/7 + menejer'],
          ['Hisobotlar',         'Asosiy',          'Kengaytirilgan',  'Maxsus'],
          ['SLA kafolati',       'icon:x',          'icon:x',          '99.9%'],
        ];
        foreach ($rows as $row): ?>
          <tr>
            <?php foreach ($row as $cell): ?>
              <td><?php
                if ($cell === 'icon:ok')      echo '<i class="bi bi-check-circle-fill"></i>';
                elseif ($cell === 'icon:x')   echo '<i class="bi bi-x"></i>';
                else echo htmlspecialchars($cell);
              ?></td>
            <?php endforeach; ?>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
  </div>

  <!-- CTA -->
  <div class="pp-cta">
    <div class="pp-cta-text">
      <div class="pp-cta-eyebrow">Yordam kerakmi</div>
      <h4>Savollaringizga javob beramiz</h4>
      <p>Integratsiya, narxlash va tarif tanlovi bo'yicha jamoamiz bilan bog'laning.</p>
    </div>
    <div class="pp-cta-btns">
      <a href="/contact" class="pp-cta-outline"><i class="bi bi-chat-dots"></i> Bog'lanish</a>
      <a href="https://<?= $_SERVER['HTTP_HOST'] ?>/billing/checkout?plan=premium" class="pp-cta-fill">
        <i class="bi bi-rocket-takeoff"></i> Premium bilan boshlash
      </a>
    </div>
  </div>

</div>

<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/business/includes/footer.php'); ?>
</body>
</html>
