<?php 
session_start();

require 'includes/db.php';
require 'includes/functions.php';
require 'includes/settings.php';
require 'includes/currency.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit;
}

$user = getUser($_SESSION['user_id']);

// ===============================
// 💱 FIX CURRENCY (DB → COOKIE)
// ===============================
$userCurrency = strtoupper($user['currency'] ?? '');

if (empty($userCurrency)) {

    $currency_cookie = $_COOKIE['currency_selected'] ?? 'USD';

    $map = [
        "R"  => "ZAR",
        "₦"  => "NGN",
        "$"  => "USD",
        "€"  => "EUR",
        "£"  => "GBP"
    ];

    $userCurrency = $map[$currency_cookie] ?? $currency_cookie;
}

$userCurrency = strtoupper(trim($userCurrency));

$allowed = ["USD","ZAR","NGN","EUR","GBP","CHF","CAD","AUD","INR"];

if (!in_array($userCurrency, $allowed)) {
    $userCurrency = "USD";
}

$_SESSION['currency'] = $userCurrency;

// ===============================
// 💱 SYMBOL
// ===============================
$currencySymbols = [
    "USD" => "$",
    "ZAR" => "R",
    "NGN" => "₦",
    "EUR" => "€",
    "GBP" => "£",
    "KES" => "KSh",
    "GHS" => "GH₵",
    "INR" => "₹",
    "AUD" => "A$",
    "CAD" => "C$"
];

$symbol = $currencySymbols[$userCurrency] ?? $userCurrency;

// ===============================
// 💰 DEFAULT BTC → LOCAL (FIXED)
// ===============================
$btc_amount = getSetting('default_amount_btc');

if (!$btc_amount || $btc_amount <= 0) {
    $btc_amount = 0.00293;
}

$btc_rate = getSetting('btc_rate');

// BTC → USD
$usd_value = $btc_amount * $btc_rate;

// USD → LOCAL
$local_value = convertCurrency($usd_value, 'USD', $userCurrency);

// ===============================
// 🚫 PAYMENT CHECK
// ===============================
if ($user['payment_status'] == 1) {
    header("Location: dashboard.php?payment=success");
    exit;
}

// ===============================
// ⏱ PAYMENT TIMER
// ===============================
if (!$user['payment_started_at']) {
    $now = date("Y-m-d H:i:s");
    mysqli_query($conn, "
        UPDATE users 
        SET payment_started_at='$now' 
        WHERE id='{$user['id']}'
    ");
    $user['payment_started_at'] = $now;
}

$expiry = strtotime($user['payment_started_at']) + 86400;
$remaining = $expiry - time();
$expiry_js = $expiry * 1000;

// ===============================
// 💳 PAYMENT DETAILS
// ===============================
$res = mysqli_query($conn, "SELECT * FROM payment_details ORDER BY id DESC LIMIT 1");
$payment = mysqli_fetch_assoc($res);

$wallet = $payment['payment_text'] ?? 'No wallet set';
$qrImage = $payment['payment_image'] ?? '';

// ===============================
// 💰 GET FEE
// ===============================
$res = mysqli_query($conn, "
    SELECT setting_value FROM system_settings 
    WHERE setting_key='account_fee_btc' LIMIT 1
");

$row = mysqli_fetch_assoc($res);
$fee = $row['setting_value'] ?? "0.0005";

// ===============================
// 💵 GET AMOUNT
// ===============================
$amount = $_GET['amount'] ?? 0;
$amount = (float)$amount;

// ===============================
// 💱 CONVERT AMOUNT + FEE
// ===============================
$amount_btc = (float)$amount;
$fee_btc    = (float)$fee;

// BTC → USD
$amount_usd = $amount_btc * $btc_rate;
$fee_usd    = $fee_btc * $btc_rate;

// USD → LOCAL
$amount_local = convertCurrency($amount_usd, 'USD', $userCurrency);
$fee_local    = convertCurrency($fee_usd, 'USD', $userCurrency);

// ===============================
// 📜 USER PAYMENT HISTORY (FIX)
// ===============================
$historyRes = mysqli_query($conn, "
    SELECT * FROM billings 
    WHERE user_id='{$user['id']}'
    ORDER BY id DESC
");

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Payment - Geneva & Exeter Coin Dashboard</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #4f46e5;
            min-height: 100vh;
            position: relative;
            overflow-x: hidden;
        }

        /* Crypto icons background pattern */
        .crypto-bg {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            overflow: hidden;
            pointer-events: none;
            z-index: 0;
        }

        .crypto-icon {
            position: absolute;
            opacity: 0.06;
            color: white;
            font-size: 48px;
            font-weight: bold;
        }

        /* Bitcoin symbols */
        .crypto-icon.btc:nth-child(1) { top: 10%; left: 5%; transform: rotate(-15deg); font-size: 64px; }
        .crypto-icon.btc:nth-child(2) { top: 70%; left: 15%; transform: rotate(10deg); font-size: 56px; }
        .crypto-icon.btc:nth-child(3) { top: 30%; right: 10%; transform: rotate(-5deg); font-size: 72px; }
        .crypto-icon.btc:nth-child(4) { bottom: 20%; right: 25%; transform: rotate(20deg); font-size: 48px; }
        .crypto-icon.btc:nth-child(5) { top: 50%; left: 40%; transform: rotate(-10deg); font-size: 60px; }

        /* Ethereum symbols */
        .crypto-icon.eth:nth-child(6) { top: 20%; left: 25%; transform: rotate(5deg); font-size: 52px; }
        .crypto-icon.eth:nth-child(7) { top: 60%; right: 5%; transform: rotate(-10deg); font-size: 60px; }
        .crypto-icon.eth:nth-child(8) { bottom: 30%; left: 8%; transform: rotate(15deg); font-size: 44px; }
        .crypto-icon.eth:nth-child(9) { top: 80%; right: 40%; transform: rotate(-5deg); font-size: 56px; }

        /* Generic crypto circle symbols */
        .crypto-icon.circle:nth-child(10) { top: 5%; left: 50%; transform: rotate(-8deg); font-size: 40px; }
        .crypto-icon.circle:nth-child(11) { top: 45%; left: 2%; transform: rotate(12deg); font-size: 36px; }
        .crypto-icon.circle:nth-child(12) { bottom: 10%; right: 8%; transform: rotate(-20deg); font-size: 52px; }
        .crypto-icon.circle:nth-child(13) { top: 85%; left: 60%; transform: rotate(8deg); font-size: 44px; }
        .crypto-icon.circle:nth-child(14) { top: 15%; right: 30%; transform: rotate(-12deg); font-size: 56px; }
        .crypto-icon.circle:nth-child(15) { bottom: 40%; left: 30%; transform: rotate(18deg); font-size: 48px; }

        /* Dashboard Navigation */
        .dashboard-nav {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 9999;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 48px;
            height: 64px;
            background: #3730a3;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }

        .nav-left {
            display: flex;
            align-items: center;
            gap: 48px;
            height: 100%;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            color: white;
            font-size: 24px;
            font-weight: 700;
            text-decoration: none;
            z-index: 10000;
            position: relative;
        }

        .logo-icon {
            width: 40px;
            height: 40px;
            background: white;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #3730a3;
            font-weight: bold;
        }

        .nav-links {
            display: flex;
            gap: 0;
            list-style: none;
            margin: 0;
            padding: 0;
            height: 100%;
            align-items: center;
        }

        .nav-links li {
            position: relative;
            z-index: 10000;
            height: 100%;
            display: flex;
            align-items: center;
        }

        /* SQUARE MENU LINKS - NO ROUNDED BORDERS */
        .nav-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            font-size: 15px;
            font-weight: 500;
            transition: all 0.2s;
            padding: 0 24px;
            height: 100%;
            display: flex;
            align-items: center;
            cursor: pointer;
            background: transparent;
            border: none;
            border-radius: 0;
            position: relative;
            z-index: 10000;
        }

        .nav-links a:hover {
            color: #ffffff;
            background: rgba(255, 255, 255, 0.1);
        }

        .nav-links a.active {
            color: #ffffff;
            background: rgba(255, 255, 255, 0.15);
            font-weight: 600;
        }

        /* Active indicator line at bottom */
        .nav-links a.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: #22c55e;
        }

        .nav-right {
            display: flex;
            align-items: center;
            gap: 24px;
            z-index: 10000;
            position: relative;
            height: 100%;
			
        }

        .balance-display {
            display: flex;
            align-items: center;
            background: rgba(255, 255, 255, 0.1);
            padding: 8px 16px;
            gap: 16px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 0;
        }

        .balance-item {
            display: flex;
            align-items: center;
            gap: 8px;
            color: #ffffff;
            font-size: 14px;
            font-weight: 600;
        }

        .balance-item.btc {
            border-right: 1px solid rgba(255, 255, 255, 0.3);
            padding-right: 16px;
        }

        .balance-item svg {
            width: 16px;
            height: 16px;
        }

        /* User Menu with Dropdown */
        .user-menu-container {
            position: relative;
        }

        .user-menu {
            display: flex;
            align-items: center;
            gap: 12px;
            color: #ffffff;
            cursor: pointer;
            padding: 8px 12px;
            transition: background 0.2s;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 0;
            height: 40px;
        }

        .user-menu:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .user-icon {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .user-icon svg {
            width: 18px;
            height: 18px;
            color: white;
        }

        .username {
            font-size: 14px;
            font-weight: 600;
            color: #ffffff;
        }

        .dropdown-icon {
            width: 16px;
            height: 16px;
            color: rgba(255, 255, 255, 0.8);
            transition: transform 0.2s;
        }

        .user-menu-container.active .dropdown-icon {
            transform: rotate(180deg);
        }

        .notification-badge {
            position: absolute;
            top: -2px;
            right: -2px;
            width: 16px;
            height: 16px;
            background: #ef4444;
            color: white;
            font-size: 10px;
            font-weight: 700;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px solid #3730a3;
        }

        /* Dropdown Menu */
        .user-dropdown {
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            background: white;
            border-radius: 12px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            min-width: 280px;
            overflow: hidden;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.2s;
            z-index: 10001;
        }

        .user-menu-container.active .user-dropdown {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        .dropdown-header {
            display: flex;
            align-items: center;
            gap: 16px;
            padding: 20px;
            background: #4f46e5;
            color: white;
        }

        .dropdown-header-icon {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px solid rgba(255, 255, 255, 0.3);
        }

        .dropdown-header-icon svg {
            width: 24px;
            height: 24px;
            color: white;
        }

        .dropdown-header-text {
            font-size: 20px;
            font-weight: 600;
        }

        .dropdown-menu {
            list-style: none;
            padding: 8px 0;
            margin: 0;
        }

        .dropdown-menu li {
            border-bottom: 1px solid #f1f5f9;
        }

        .dropdown-menu li:last-child {
            border-bottom: none;
        }

        .dropdown-menu a {
            display: flex;
            align-items: center;
            gap: 16px;
            padding: 16px 20px;
            color: #475569;
            text-decoration: none;
            font-size: 16px;
            font-weight: 500;
            transition: background 0.2s;
        }

        .dropdown-menu a:hover {
            background: #f8fafc;
        }

        .dropdown-menu-icon {
            width: 24px;
            height: 24px;
            color: #4f46e5;
        }

        .dropdown-menu-icon.logout {
            color: #ef4444;
        }

        /* Unread Badge */
        .unread-badge {
            background: #ec4899;
            color: white;
            font-size: 13px;
            font-weight: 600;
            padding: 6px 16px;
            border-radius: 20px;
            margin-left: auto;
        }

        .dropdown-menu a.logout-link {
            color: #ef4444;
        }

        .dropdown-menu a.logout-link:hover {
            background: #fef2f2;
        }

        /* Main Content Area */
        .main-content {
            position: relative;
            z-index: 10;
            min-height: 100vh;
            padding: 100px 48px 120px;
            background: #4f46e5;
        }

        /* Welcome Section */
        .welcome-section {
            margin-bottom: 32px;
        }

        .welcome-text {
            color: white;
            font-size: 24px;
            font-weight: 600;
        }

        /* Payment Grid */
        .payment-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 24px;
            max-width: 1400px;
        }

        /* Card Styles */
        .payment-card {
            background: #f8fafc;
            border-radius: 12px;
            padding: 32px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 24px;
        }

        .card-title {
            font-size: 16px;
            font-weight: 700;
            color: #1e1b4b;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .expiry-timer {
            font-size: 14px;
            color: #1e1b4b;
            font-weight: 600;
        }

        /* Progress Bar */
        .progress-bar {
            width: 100%;
            height: 8px;
            background: #e2e8f0;
            border-radius: 4px;
            margin-bottom: 24px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            width: 85%;
            background: #6366f1;
            border-radius: 4px;
        }

        /* Payment Details */
        .detail-row {
            margin-bottom: 24px;
            padding-bottom: 24px;
            border-bottom: 1px solid #e2e8f0;
        }

        .detail-row:last-child {
            border-bottom: none;
        }

        .detail-label {
            font-size: 14px;
            font-weight: 700;
            color: #1e1b4b;
            text-transform: uppercase;
            margin-bottom: 8px;
            display: block;
        }

        .detail-value {
            font-size: 16px;
            color: #4f46e5;
            font-weight: 600;
            word-break: break-all;
        }

        .copy-btn {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            margin-top: 8px;
            color: #64748b;
            font-size: 14px;
            cursor: pointer;
            background: none;
            border: none;
            padding: 0;
        }

        .copy-btn:hover {
            color: #4f46e5;
        }

        /* QR Code Section */
        .qr-section {
            margin: 24px 0;
        }

        .qr-code {
            width: 200px;
            height: 200px;
            background: white;
            padding: 12px;
            margin-bottom: 12px;
        }

        .qr-hint {
            font-size: 13px;
            color: #64748b;
            line-height: 1.5;
        }

        /* Remarks Section */
        .remarks-section {
            margin-top: 24px;
            padding-top: 24px;
            border-top: 1px solid #e2e8f0;
        }

        .remarks-text {
            font-size: 15px;
            color: #334155;
            line-height: 1.7;
        }

        .remarks-text p {
            margin-bottom: 12px;
        }

        .remarks-text p:last-child {
            margin-bottom: 0;
        }

        /* FAQ Section */
        .faq-section {
            margin-top: 48px;
            padding-top: 32px;
            border-top: 2px solid #e2e8f0;
        }

        .faq-title {
            font-size: 20px;
            font-weight: 700;
            color: #1e1b4b;
            margin-bottom: 24px;
        }

        .faq-item {
            border-bottom: 1px solid #e2e8f0;
            padding: 20px 0;
        }

        .faq-item:last-child {
            border-bottom: none;
        }

        .faq-question {
            font-size: 17px;
            font-weight: 600;
            color: #1e1b4b;
            margin-bottom: 12px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .faq-question:hover {
            color: #4f46e5;
        }

        .faq-answer {
            font-size: 15px;
            color: #64748b;
            line-height: 1.7;
            padding-left: 0;
        }

        /* History Card */
        .history-hint {
            font-size: 14px;
            color: #64748b;
            margin-bottom: 24px;
            padding-bottom: 16px;
            border-bottom: 1px solid #e2e8f0;
        }

        .empty-state {
            text-align: center;
            padding: 48px 0;
        }

        .empty-text {
            font-size: 16px;
            color: #1e1b4b;
            font-weight: 500;
            margin-bottom: 24px;
        }

        .status-indicator {
            width: 48px;
            height: 48px;
            border: 2px solid #22c55e;
            border-radius: 50%;
            margin: 0 auto;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .status-dot {
            width: 16px;
            height: 16px;
            background: #22c55e;
            border-radius: 50%;
        }

        /* Footer */
        .dashboard-footer {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            z-index: 9999;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 48px;
            height: 80px;
            background: #4f46e5;
            border-top: 1px solid rgba(255, 255, 255, 0.2);
        }

        .footer-left {
            display: flex;
            align-items: center;
            gap: 32px;
        }

        .footer-logo {
            width: 48px;
            height: 48px;
            background: white;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #4f46e5;
            font-size: 24px;
            font-weight: bold;
            text-decoration: none;
        }

        .footer-links {
            display: flex;
            gap: 32px;
            list-style: none;
            margin: 0;
            padding: 0;
        }

        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            font-size: 15px;
            font-weight: 500;
            transition: color 0.2s;
        }

        .footer-links a:hover {
            color: #ffffff;
        }

        .footer-right {
            text-align: right;
            color: rgba(255, 255, 255, 0.8);
            font-size: 14px;
            line-height: 1.6;
        }

        .footer-right p {
            margin: 0;
        }

        /* Floating animation for background icons */
        @keyframes float {
            0%, 100% { transform: translateY(0) rotate(var(--rotation, 0deg)); }
            50% { transform: translateY(-10px) rotate(var(--rotation, 0deg)); }
        }

        .crypto-icon {
            animation: float 6s ease-in-out infinite;
        }

        .crypto-icon:nth-child(odd) { animation-delay: 0s; }
        .crypto-icon:nth-child(even) { animation-delay: 3s; }

        /* Responsive */
        @media (max-width: 1024px) {
            .payment-grid {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 768px) {
            .dashboard-nav {
                padding: 0 24px;
            }

            .nav-links {
                display: none;
            }

            .balance-display {
                display: none;
            }

            .main-content {
                padding: 100px 24px 120px;
            }

            .payment-card {
                padding: 24px;
            }

            .user-dropdown {
                right: -12px;
                min-width: 260px;
            }

            .dashboard-footer {
                padding: 0 24px;
                flex-direction: column;
                height: auto;
                padding-top: 20px;
                padding-bottom: 20px;
                gap: 16px;
            }

            .footer-left {
                flex-direction: column;
                gap: 16px;
            }

            .footer-right {
                text-align: center;
            }
        }
		.timer-box {
    width: 100%;
    max-width: 600px;
    margin: 20px auto;
}

.timer-text {
    text-align: right;
    font-weight: bold;
    color: #1e1b4b;
    margin-bottom: 10px;
    font-size: 16px;
}

/* Background bar */
.progress-bar {
    width: 100%;
    height: 12px;
    background: #e5e7eb;
    border-radius: 20px;
    overflow: hidden;
}

/* Animated fill */
.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #6366f1);
    border-radius: 20px;
    transition: width 1s linear;
}


        .amount {
            font-size:15px;
            color:#22c55e;
            margin:14px 0;
        }

        .wallet {
			background:#393;
            padding:12px;
            border-radius:8px;
			color:#FFF;
            font-size:14px;
            word-break:break-all;
        }

        .copy-btn {
            margin-top:10px;
            padding:10px;
            background:#2563eb;
            border:none;
            color:#fff;
            border-radius:6px;
            cursor:pointer;
        }

        .copy-btn:hover {
            background:#1d4ed8;
        }

        .qr img {
            width:200px;
            height:200px;
            border-radius:8px;
            background:#fff;
            padding:10px;
        }

        .info {
            font-size:14px;
            color:#94a3b8;
            margin-top:10px;
        }

        .warning {
            color:#f87171;
            margin-top:15px;
        }

        .status {
            margin-top:15px;
            color:#facc15;
            font-weight:bold;
        }

        .timer {
            margin-top:10px;
            font-size:14px;
            color:#94a3b8;
        }
		.history-item:hover {
    background: #f1f5f9;
}
/* ================= GLOBAL RESPONSIVE FIX ================= */

/* LOGO */
.logo-img{
    width:180px;
    height:auto;
    max-width:100%;
}

/* GRID FIX */
.payment-grid{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:24px;
}

/* CARD FLEXIBILITY */
.payment-card{
    width:100%;
}

/* QR IMAGE FIX */
.qr img{
    max-width:100%;
    height:auto;
}

/* WALLET BOX */
.wallet{
    word-break:break-word;
}

/* HISTORY ITEMS */
.history-item{
    width:100%;
}

/* ================= TABLET ================= */
@media (max-width:1024px){

    .payment-grid{
        grid-template-columns:1fr;
    }

}

/* ================= MOBILE ================= */
@media (max-width:768px){

    /* NAV */
    .dashboard-nav{
        padding:0 16px;
    }

    .nav-links{
        display:none;
    }

    .balance-display{
        display:none!important;
    }

    .user-menu-container{
        display:none!important;
    }

    .logo-img{
        width:140px;
    }

    /* MAIN CONTENT */
    .main-content{
        padding:90px 16px 120px;
    }

    .welcome-text{
        font-size:20px;
    }

    /* CARD */
    .payment-card{
        padding:20px;
        border-radius:14px;
    }

    /* QR */
    .qr img{
        width:100%;
        max-width:220px;
    }

    /* TEXT FIX */
    .detail-value{
        font-size:14px;
    }

    .remarks-text{
        font-size:14px;
    }

    /* FOOTER STACK */
    .dashboard-footer{
        position:relative;
        flex-direction:column;
        height:auto;
        padding:20px;
        gap:12px;
        text-align:center;
    }

    .footer-left{
        flex-direction:column;
        gap:12px;
    }

    .footer-links{
        flex-direction:column;
        gap:8px;
    }

    .footer-right{
        text-align:center;
        font-size:12px;
    }

}

/* ================= SMALL PHONES ================= */
@media (max-width:480px){

    .logo-img{
        width:120px;
    }

    .payment-card{
        padding:16px;
    }

    .card-title{
        font-size:14px;
    }

    .amount{
        font-size:14px;
    }

}
/* ================= RESPONSIVE FIX ================= */

/* LOGO */
.logo-img{
    width:180px;
    height:auto;
    max-width:100%;
}

/* HAMBURGER */
.hamburger{
    display:none;
    flex-direction:column;
    gap:4px;
    cursor:pointer;
}
.hamburger span{
    width:25px;
    height:3px;
    background:#fff;
}

/* MOBILE MENU */
.mobile-menu{
    position:fixed;
    top:0;
    left:-260px;
    width:260px;
    height:100%;
    background:#3730a3;
    padding-top:80px;
    transition:.3s;
    z-index:9999;
}
.mobile-menu a{
    display:block;
    padding:15px 20px;
    color:#fff;
    text-decoration:none;
}
.mobile-menu.active{left:0}

/* OVERLAY */
.menu-overlay{
    position:fixed;
    top:0;left:0;right:0;bottom:0;
    background:rgba(0,0,0,.5);
    opacity:0;
    visibility:hidden;
    transition:.3s;
}
.menu-overlay.active{
    opacity:1;
    visibility:visible;
}

/* 📱 MOBILE */
@media (max-width:768px){

    .hamburger{
        display:flex;
    }

    .nav-links{
        display:none;
    }

    .balance-display{
        display:none!important;
    }

    .user-menu-container{
        display:none!important;
    }

    .logo-img{
        width:140px;
    }

    .main-content{
        padding:90px 15px 120px;
    }

    .card{
        padding:30px 20px;
        border-radius:16px;
    }

    .card-title{
        font-size:22px;
    }

    .btn{
        padding:16px;
        font-size:16px;
    }

    /* FOOTER STACK */
    .dashboard-footer{
        flex-direction:column;
        height:auto;
        padding:20px;
        gap:15px;
        text-align:center;
    }

    .footer-left{
        flex-direction:column;
        gap:10px;
    }

    .footer-links{
        flex-direction:column;
        gap:8px;
    }

    .footer-right{
        text-align:center;
    }
}
/* ================= FOOTER RESPONSIVE ================= */

/* DESKTOP DEFAULT */
.dashboard-footer{
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    display: flex;
    justify-content: space-between;
    align-items: center;

    padding: 0 40px;
    height: 80px;

    background: #4f46e5;
    border-top: 1px solid rgba(255,255,255,0.2);
    z-index: 9999;
}

/* LEFT */
.footer-left{
    display: flex;
    align-items: center;
    gap: 30px;
}

/* LOGO */
.footer-logo{
    width: 48px;
    height: 48px;
    background: #fff;
    color: #4f46e5;
    font-weight: bold;
    font-size: 20px;
    border-radius: 12px;

    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

/* LINKS */
.footer-links{
    display: flex;
    gap: 25px;
    list-style: none;
}

.footer-links a{
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 14px;
}

.footer-links a:hover{
    color: #fff;
}

/* RIGHT */
.footer-right{
    text-align: right;
    color: rgba(255,255,255,0.8);
    font-size: 13px;
}

/* ================= MOBILE ================= */
@media (max-width: 768px){

    .dashboard-footer{
        position: relative; /* 🔥 prevents overlap */
        flex-direction: column;
        height: auto;
        padding: 20px;
        gap: 15px;
        text-align: center;
    }

    .footer-left{
        flex-direction: column;
        gap: 15px;
    }

    .footer-links{
        flex-direction: column;
        gap: 10px;
        align-items: center;
    }

    .footer-right{
        text-align: center;
        font-size: 12px;
    }
}
/* Button */
        .btn {
            margin-top: 30px;
            display: inline-block;
            background: #22c55e;
            color: white;
            padding: 18px 40px;
            border-radius: 12px;
            text-decoration: none;
            font-size: 18px;
            font-weight: 700;
            transition: all 0.2s;
            border: none;
            cursor: pointer;
            width: 100%;
        }

        .btn:hover {
            background: #16a34a;
            transform: translateY(-2px);
            box-shadow: 0 10px 30px rgba(34, 197, 94, 0.4);
        }

    </style>
    
</head>
<body>
    <!-- Crypto icons background -->
    <div class="crypto-bg">
        <!-- Bitcoin symbols -->
        <div class="crypto-icon btc">₿</div>
        <div class="crypto-icon btc">₿</div>
        <div class="crypto-icon btc">₿</div>
        <div class="crypto-icon btc">₿</div>
        <div class="crypto-icon btc">₿</div>
        
        <!-- Ethereum symbols -->
        <div class="crypto-icon eth">◊</div>
        <div class="crypto-icon eth">◊</div>
        <div class="crypto-icon eth">◊</div>
        <div class="crypto-icon eth">◊</div>
        
        <!-- Circle/generic crypto symbols -->
        <div class="crypto-icon circle">◎</div>
        <div class="crypto-icon circle">◎</div>
        <div class="crypto-icon circle">◎</div>
        <div class="crypto-icon circle">◎</div>
        <div class="crypto-icon circle">◎</div>
        <div class="crypto-icon circle">◎</div>
    </div>

    <!-- Dashboard Navigation -->
    <nav class="dashboard-nav">
        <div class="nav-left">

    <!-- HAMBURGER -->
    <div class="hamburger" onclick="toggleMenu()">
        <span></span>
        <span></span>
        <span></span>
    </div>
           <a href="#" class="logo">
                <img src="img/logo_white.png" class="logo-img">
            </a>
            <ul class="nav-links">
                <li><a href="#">Dashboard</a></li>
                <li><a href="#" class="active">Deposit</a></li>
                <li><a href="#">Withdraw</a></li>
                <li><a href="#">Portfolio</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </div>
        <div class="nav-right">
            <div class="balance-display">
                <div class="balance-item btc">
                    <span> <div><?php if (is_numeric($local_value)) {
    echo "" 
        . $symbol . number_format($local_value, 2) . "";
} else {
    echo "($local_value)";
} ?></div></span>
                    <svg viewBox="0 0 24 24" fill="currentColor">
                        <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm.5-13H11v2h-1v2h1v4h-1v2h1v2h1.5v-2h1v-2h-1v-4h1V9h-1V7z"/>
                    </svg>
                </div>
                <div class="balance-item">
                    <span> <?php  echo number_format($btc_amount, 2) . " BTC ";   ?> </span>
                </div>
            </div>
            
            <!-- User Menu with Dropdown -->
            <div class="user-menu-container" id="userMenuContainer">
                <div class="user-menu" onclick="toggleDropdown()">
                    <div class="user-icon" style="position: relative;">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                            <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                            <circle cx="12" cy="7" r="4"></circle>
                        </svg>
                    </div>
                    <svg class="dropdown-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <polyline points="6 9 12 15 18 9"></polyline>
                    </svg>
                </div>
                
                <!-- Dropdown Menu -->
                <div class="user-dropdown">
                    <div class="dropdown-header">
                        <div class="dropdown-header-icon">
                            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                                <circle cx="12" cy="7" r="4"></circle>
                            </svg>
                        </div> <span class="dropdown-header-text"><?php echo $user['customer_id']; ?></span>
                    </div>
                    <ul class="dropdown-menu">
                        
                        
                        <li>
                            <a href="logout.php" class="logout-link">
                                <svg class="dropdown-menu-icon logout" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                    <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
                                    <polyline points="16 17 21 12 16 7"></polyline>
                                    <line x1="21" y1="12" x2="9" y2="12"></line>
                                </svg>
                                Logout
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </nav>
<div class="mobile-menu" id="mobileMenu">
    <a href="#">Dashboard</a>
    <a href="#">Deposit</a>
    <a href="#">Withdraw</a>
    <a href="#">Referral</a>
</div>

<div class="menu-overlay" id="menuOverlay" onclick="toggleMenu()"></div>
    <!-- Main Content -->
    <div class="main-content">
      <div class="payment-grid">
          <!-- Invoice Payment Details Card -->
          <div class="payment-card">
                <div class="card-header">
                    <h2 class="card-title">Deposit BTC</h2>
                    
                </div>

              <div class="">
                  <div class="box">
                    <?php echo "
<div style='
    background:linear-gradient(145deg,#110D59,#1e293b);
    padding:25px;
    border-radius:20px;
    color:#fff;
    max-width:100%;
    margin:auto;
    font-family:sans-serif;
'>

    <!-- HEADER -->
    <div style='display:flex;align-items:center;gap:10px;margin-bottom:15px;'>
        <div style='width:30px;height:30px;background:#fff;border-radius:6px;'></div>
        <h3 style='margin:0;'>Crypto Payment</h3>
    </div>

    <!-- BTC AMOUNT -->
    <div style='font-size:28px;font-weight:700;letter-spacing:1px;'>
        "  . number_format($fee_btc, 6) . " BTC
    </div>

    <!-- LOCAL -->
<div style='margin-top:5px;color:#94a3b8;font-size:14px;'>
    " . $symbol . number_format($fee_local, 2) .  "
</div>

<!-- FEES -->
<div style='margin-top:8px;font-size:13px;color:#94a3b8;'>

    Fees: 
    <strong style='color:#fff;'>"
        . number_format($fee_btc, 6) . " BTC
    </strong>
~
    <span style='color:#64748b;'>
        (" . $symbol . number_format($fee_local, 2) . ")
    </span>

</div>

    <!-- NETWORK -->
    <div style='margin-top:10px;font-size:13px;color:#94a3b8;'>
        Network · BTC
    </div>

    <!-- FEE NOTE -->
    <div style='margin-top:8px;font-size:12px;color:#64748b;'>
        You pay network fee
    </div>
	<br>
	<!-- WALLET -->
        <div style='flex:1;'>

            <div style='font-size:13px;color:#94a3b8;margin-bottom:5px;'>
                Recipient's wallet address
            </div>
<br>
            <div style='
                background:#020617;
                padding:8px;
                border-radius:8px;
                font-size:12px;
                word-break:break-all;
                display:flex;
                justify-content:space-between;
                align-items:center;
                gap:1px;
            '>

                <span id='walletText'>{$wallet}</span>

				
				
				
				<button onclick='copyWallet()'
    style='background:#4f46e5;border:none;color:#fff;
    padding:6px;border-radius:6px;cursor:pointer;'>
    
    <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' viewBox='0 0 24 24'>
        <path d='M16 1H4C2.9 1 2 1.9 2 3V15H4V3H16V1ZM19 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H19C20.1 23 21 22.1 21 21V7C21 5.9 20.1 5 19 5ZM19 21H8V7H19V21Z'/>
    </svg>

</button>
				
				
            </div>

        </div>

    <hr style='border:1px solid #1e293b;margin:20px 0;'>

    <!-- QR + WALLET -->
    <div style='display:flex;gap:15px;align-items:center;'>

        <!-- QR -->
        <img src='uploads/{$qrImage}' 
            style='width:100px;height:100px;border-radius:3px;background:#fff;padding:5px;'>

        
    </div>

    <hr style='border:1px solid #1e293b;margin:20px 0;'>

    <!-- FOOTER STATUS -->
    <div style='display:flex;justify-content:space-between;align-items:center;'>

        <!-- TIMER -->
        <div>
            <div style='font-size:12px;color:#94a3b8;'>Expiration time</div>
            <div style='color:#22c55e;font-weight:600;'>
                <span id='timer'>Loading...</span>
            </div>
        </div>

        <!-- STATUS -->
        <div style='text-align:right;'>
            <div style='font-size:12px;color:#94a3b8;'>Checking blockchain</div>
            <div style='color:#22c55e;font-size:13px;'>● Active</div>
        </div>

    </div>

</div>
";
?>

    <!-- QR CODE -->

    <div class="timer" id="timer">
      
    </div>

    <hr>

    <p class="info">
        If payment is not confirmed automatically, kindly upload proof of payment.
  </p> 
    <a href="upload_proof.php" target="_self">
    <button class="btn">Upload proof of payment</button>
    </a>
                </div></div>

                <!-- Remarks Section -->
                <div class="remarks-section">
                    <span class="detail-label">REMARKS :</span>
                    <div class="remarks-text">
                        <p>Payment of annual OTP network charge is compulsory and must be done before account access.</p>
                        <p>Your invoice can only accept Bitcoin(BTC) payments. Other cryptocurrencies such as Ethereum(ETH), Litecoin(LTC) or Bitcoin-cash(BCH) are not accepted.</p>
                          
                    </div>
              </div>

                <!-- FAQ Section -->
                <div class="faq-section">
                  <div class="faq-item">
                    <div class="faq-answer">If you created a portfolio for say 10 BTC and ended up funding it with 12 BTC, at the end of your chosen tenure, your interest will be calculated with 12 BTC.
                    </div>
                  </div>
              </div>
        </div>

            <!-- Payment History Card -->
            <div class="payment-card">
                <div class="card-header">
                    <h2 class="card-title">PAYMENT(S) HISTORY</h2>
                </div>

                <p class="history-hint">You will be auto-redirected to dashboard after invoice payment</p>

                <?php if(mysqli_num_rows($historyRes) > 0): ?>

    <?php while($row = mysqli_fetch_assoc($historyRes)): ?>

        <div class="history-item" style="padding:15px;border-bottom:1px solid #e2e8f0;">
            
            <div style="display:flex;justify-content:space-between;">
                
                <div>
                    <strong><?php echo htmlspecialchars($row['description']); ?></strong><br>
                    <small style="color:#64748b;">
                        <?php echo date("M d, Y H:i", strtotime($row['created_at'])); ?>
                    </small>
                </div>

                <div style="text-align:right;">
                    <div style="font-weight:bold;color:#4f46e5;">
                        <?php echo rtrim(rtrim(number_format($row['amount'], 8, '.', ''), '0'), '.'); ?> BTC
                    </div>

                    <div style="
                        font-size:12px;
                        color:
                        <?php echo $row['status'] == 'paid' ? '#22c55e' : '#facc15'; ?>;
                    ">
                        <?php echo ucfirst($row['status']); ?>
                    </div>
                </div>

            </div>

        </div>

    <?php endwhile; ?>

<?php else: ?>

    <div class="empty-state">
        <p class="empty-text">No payment history yet</p>
    </div>

<?php endif; ?>
            </div>
      </div>
</div>

    <!-- Footer -->
    <footer class="dashboard-footer">
        
        <div class="footer-right">
            <p>&copy; <?php echo date("Y"); ?>  Geneva & Exeter Coin. All rights reserved.</p>
        </div>
    </footer>

    <script>
        function toggleDropdown() {
            const container = document.getElementById('userMenuContainer');
            container.classList.toggle('active');
        }

        // Close dropdown when clicking outside
        document.addEventListener('click', function(event) {
            const container = document.getElementById('userMenuContainer');
            if (!container.contains(event.target)) {
                container.classList.remove('active');
            }
        });
		
	// 🔥 TIMER FIXED (NO RESET)
let endTime = <?php echo $expiry_js; ?>;
let totalTime = 86400;

function updateTimer() {

    let now = Date.now();
    let remaining = Math.max(0, Math.floor((endTime - now) / 1000));

    let d = Math.floor(remaining / 86400);
    let h = Math.floor((remaining % 86400) / 3600);
    let m = Math.floor((remaining % 3600) / 60);
    let s = remaining % 60;

    document.getElementById("timerText").innerHTML =
        `Expiring: ${d}d ${h}h ${m}m ${s}s`;

    let elapsed = totalTime - remaining;
    let percent = (elapsed / totalTime) * 100;

    document.getElementById("progressFill").style.width = percent + "%";

    if (remaining <= 0) {
        document.getElementById("timerText").innerHTML = "Expired";
    }
}

setInterval(updateTimer, 1000);
updateTimer();


// 💱 BTC → FIAT
let btcAmount = <?php echo $btc_amount; ?>;
let userCurrency = "<?php echo $user_currency; ?>";

fetch("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd")
.then(res => res.json())
.then(data => {

    let btcUSD = data.bitcoin.usd;
    let usd = btcAmount * btcUSD;

    return fetch("https://open.er-api.com/v6/latest/USD")
    .then(res => res.json())
    .then(rate => {

        let final = usd * (rate.rates[userCurrency] || 1);

        document.getElementById("fiatAmount").innerHTML =
            "(" + final.toLocaleString(undefined,{minimumFractionDigits:2}) + " " + userCurrency + ")";
    });
});
    </script>
<script>
// 🔥 CHECK PAYMENT STATUS EVERY 3 SECONDS
function checkPaymentStatus() {

    fetch("check_payment.php?nocache=" + Date.now())
    .then(res => res.text())
    .then(status => {

        status = status.trim();

        console.log("Payment status:", status);

        if (status == "1") {

            // Optional message
            document.querySelector(".status").innerHTML = "✅ Payment confirmed! Redirecting...";

            setTimeout(() => {
                window.location.href = "dashboard.php?payment=success";
            }, 1500);
        }

    })
    .catch(err => console.log("Error:", err));
}

// Run every 3 seconds
setInterval(checkPaymentStatus, 3000);

// Run immediately
checkPaymentStatus();
</script>
<script>
// 🔥 Refresh page every 10 seconds (faster detection)
setTimeout(function(){
    location.reload();
}, 10000);
</script>
<script>
function toggleMenu(){
    document.getElementById("mobileMenu").classList.toggle("active");
    document.getElementById("menuOverlay").classList.toggle("active");
}
</script>
<script>
function copyWallet() {
    const text = document.getElementById("walletText").innerText;
    navigator.clipboard.writeText(text);
    alert("Wallet copied!");
}
</script>
<script>
let expiry = <?php echo $expiry_js; ?>;

function updateTimer() {
    let now = new Date().getTime();
    let distance = expiry - now;

    if (distance <= 0) {
        document.getElementById("timer").innerHTML = "Expired";
        return;
    }

    let hours = Math.floor(distance / (1000 * 60 * 60));
    let minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    let seconds = Math.floor((distance % (1000 * 60)) / 1000);

    document.getElementById("timer").innerHTML =
        hours + ":" + minutes + ":" + seconds;
}

setInterval(updateTimer, 1000);
updateTimer();
</script>
</body>
</html>