<div class="ads">
    <?= $settings['dashboard_top_ad'] ?>
</div>

<style>
:root{
    --acc-cyan:#22D3EE;
    --acc-cyan-dim:rgba(34,211,238,.14);
    --acc-indigo:#6366F1;
    --acc-indigo-dim:rgba(99,102,241,.14);
    --acc-emerald:#34D399;
    --acc-emerald-dim:rgba(52,211,153,.14);
    --acc-amber:#FBBF24;
    --acc-amber-dim:rgba(251,191,36,.14);
    --acc-rose:#FB7185;
    --acc-rose-dim:rgba(251,113,133,.14);
}

.badge{font-size:100%;}

.ref-banner{
    display:flex;align-items:center;justify-content:center;gap:10px;
    background:linear-gradient(135deg, rgba(34,211,238,.14), rgba(99,102,241,.10));
    border:1px solid var(--line);border-radius:16px;padding:14px 18px;margin-bottom:22px;
    color:var(--text);font-weight:700;font-size:14px;text-align:center;letter-spacing:.02em;
}
.ref-banner i{color:var(--acc-amber);font-size:16px;}

.ref-card{
    background:var(--surface);border:1px solid var(--line);border-radius:18px;
    border-top:3px solid transparent;overflow:hidden;
}
.ref-card.acc-cyan{border-top-color:var(--acc-cyan);}
.ref-card.acc-emerald{border-top-color:var(--acc-emerald);}
.ref-card .card-body{padding:24px;}

.ref-card-title{
    font-family:var(--font-display);letter-spacing:.03em;font-size:19px;color:var(--text);
    display:flex;align-items:center;gap:10px;margin-bottom:4px;
}
.ref-icon{
    width:32px;height:32px;border-radius:10px;display:flex;align-items:center;justify-content:center;
    font-size:14px;flex-shrink:0;
}
.ref-icon.cyan{background:var(--acc-cyan-dim);color:var(--acc-cyan);}
.ref-icon.emerald{background:var(--acc-emerald-dim);color:var(--acc-emerald);}

.ref-intro{color:var(--text-dim);font-size:14px;margin:14px 0;}
.ref-pct{
    display:inline-flex;align-items:center;font-family:var(--font-mono);font-weight:700;
    background:var(--acc-amber-dim);color:var(--acc-amber);padding:2px 10px;border-radius:999px;font-size:13px;
}

/* -------- Nav tabs -------- */
#iconTab.nav-tabs, .nav-tabs{
    border-bottom:1px solid var(--line) !important;gap:4px;
}
#iconTab.nav-tabs .nav-link, .nav-tabs .nav-link{
    border:none !important;background:transparent !important;color:var(--text-dim) !important;
    font-weight:700;font-size:13px;letter-spacing:.02em;border-radius:10px 10px 0 0 !important;
    padding:9px 16px !important;
}
#iconTab.nav-tabs .nav-link:hover, .nav-tabs .nav-link:hover{color:var(--text) !important;}
#iconTab.nav-tabs .nav-link.active, .nav-tabs .nav-link.active{
    color:#fff !important;background:var(--surface-2) !important;
    box-shadow:inset 0 -3px 0 0 var(--acc-cyan);
}

/* -------- Referral link input -------- */
.ref-link-group{
    display:flex;align-items:stretch;border:1px solid var(--line);border-radius:12px;
    overflow:hidden;background:var(--surface-3);
}
.ref-link-icon{
    display:flex;align-items:center;justify-content:center;padding:0 14px;
    color:var(--text-dim);background:var(--surface-2);border-right:1px solid var(--line);
}
.ref-link-input{
    flex:1;background:transparent !important;border:none !important;color:var(--text) !important;
    padding:11px 12px;font-family:var(--font-mono);font-size:13px;outline:none;
}
.ref-copy-btn{
    border:none;background:linear-gradient(120deg, var(--acc-cyan), var(--acc-indigo));color:#04101a;font-weight:700;font-size:12.5px;
    padding:0 18px;cursor:pointer;display:flex;align-items:center;gap:6px;white-space:nowrap;
    transition:filter .15s ease;
}
.ref-copy-btn:hover{filter:brightness(1.1);}

/* -------- referral stats strip -------- */
.ref-stats{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-top:20px;}
.ref-stat{
    background:var(--surface-3);border:1px solid var(--line);border-radius:14px;padding:14px 16px;text-align:center;
}
.ref-stat .rv{font-family:var(--font-mono);font-weight:700;font-size:18px;color:var(--text);}
.ref-stat .rl{font-size:10.5px;color:var(--text-dim);text-transform:uppercase;letter-spacing:.04em;margin-top:4px;}
@media (max-width:640px){ .ref-stats{grid-template-columns:1fr;} }

/* -------- Share buttons -------- */
.article-share{margin-bottom:4px;display:flex;flex-wrap:wrap;gap:10px;}
.share-btn{
    display:inline-flex !important;align-items:center;gap:6px;float:none !important;margin:0 !important;
    text-decoration:none;padding:10px 16px;border-radius:10px;color:#fff;font-size:13px;font-weight:700;
    transition:filter .15s ease, transform .15s ease;
}
.share-btn:hover{filter:brightness(1.12);transform:translateY(-1px);color:#fff;}
.share-btn-telegram{background:linear-gradient(135deg,#3C8CFF,#2563EB);}
.share-btn-twitter{background:linear-gradient(135deg,#3CC8FF,#1AA6E0);}
.share-btn-vk{background:linear-gradient(135deg,#34D399,#0E9E71);}

/* -------- Banners tab -------- */
.ref-textarea{
    background:var(--surface-3) !important;border:1px solid var(--line) !important;
    color:var(--text-dim) !important;border-radius:10px !important;font-family:var(--font-mono);font-size:12px;
}

/* -------- Referrals table -------- */
.ref-table{width:100%;border-collapse:collapse;color:var(--text);}
.ref-table thead th{
    background:transparent !important;color:var(--text-dim) !important;font-size:11px;
    text-transform:uppercase;letter-spacing:.05em;border-bottom:1px solid var(--line) !important;
    border-top:none !important;padding:10px 8px;font-weight:700;
}
.ref-table tbody tr{background:transparent !important;transition:background .15s ease;}
.ref-table tbody tr:hover{background:var(--surface-2) !important;}
.ref-table tbody td,.ref-table tbody th{
    padding:10px 8px;border-bottom:1px solid var(--line) !important;border-top:none !important;
    font-size:13.5px;vertical-align:middle;
}
.ref-table tbody tr:last-child td,.ref-table tbody tr:last-child th{border-bottom:none !important;}
.ref-earned{
    display:inline-flex;align-items:center;padding:3px 10px;border-radius:999px;
    background:var(--acc-emerald-dim);color:var(--acc-emerald);font-family:var(--font-mono);font-size:12px;font-weight:700;
}
.ref-empty{
    text-align:center;padding:34px 16px;color:var(--text-dim);font-size:13.5px;
}
.ref-empty i{font-size:26px;color:var(--acc-cyan);opacity:.6;margin-bottom:10px;display:block;}
</style>

<?php
if (isset($_SESSION['message'])) {
    echo $_SESSION['message'];
}
?>

<div class="ref-banner">
    <i class="fas fa-bullhorn"></i>
    REFER & EARN UNLIMITED INCOME!
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="card ref-card acc-cyan">
            <div class="card-body">

                <ul class="nav nav-tabs mb-3 mt-3" id="iconTab" role="tablist">
                    <li class="nav-item">
                        <a class="nav-link active" id="reflink-tab" data-toggle="tab" href="#reflink" role="tab" aria-controls="reflink" aria-selected="true">
                            Referral Link</a>
                    </li>
                    <!--
                    <li class="nav-item">
                        <a class="nav-link" id="refbann-tab" data-toggle="tab" href="#refbann" role="tab" aria-controls="refbann" aria-selected="false">
                            Banners</a>
                    </li>
                    -->
                </ul>
                <div class="tab-content" id="iconTabContent-1">

                    <div class="tab-pane fade active show" id="reflink" role="tabpanel" aria-labelledby="reflink-tab">
                        <h4 class="ref-card-title"><span class="ref-icon cyan"><i class="fas fa-share-alt"></i></span> Referral Link</h4>
                        <p class="ref-intro">Earn Gift referral program is a great way to spread the word of this great earning site and to earn even more money!</p>
                        <p class="ref-intro">Refer friends and receive <span class="ref-pct"><?= $settings['referral'] ?>%</span> of your referral's earnings lifetime!</p>

                        <div class="row mt-2">
                            <div class="col-sm-7">
                                <div class="ref-link-group">
                                    <span class="ref-link-icon"><i class="fas fa-link"></i></span>
                                    <input id="refLinkInput" type="text" class="ref-link-input" value="<?= site_url('/?r=' . $user['id']) ?>" readonly onfocus="javascript:this.select()">
                                    <button type="button" class="ref-copy-btn" onclick="copyRefLink()"><i class="far fa-copy"></i> Copy</button>
                                </div>
                            </div>
                        </div>

                        <div class="ref-stats">
                            <div class="ref-stat"><div class="rv"><?= count($referrals) ?></div><div class="rl">Total Referrals</div></div>
                            <div class="ref-stat"><div class="rv"><?= $settings['referral'] ?>%</div><div class="rl">Commission Rate</div></div>
                            <div class="ref-stat"><div class="rv">Lifetime</div><div class="rl">Payout Duration</div></div>
                        </div>

                        <div class="article-share mt-4">
                            <a class="share-btn share-btn-telegram" href="https://telegram.me/share/url?url=<?= site_url('/?r=' . $user['id']) ?>" rel="nofollow" target="_blank">
                                <i class="fab fa-telegram"></i> <span>Telegram</span>
                            </a>
                            <a class="share-btn share-btn-twitter" href="https://twitter.com/share?url=<?= site_url('/?r=' . $user['id']) ?>" rel="nofollow" target="_blank">
                                <i class="fab fa-twitter"></i> <span>Twitter</span>
                            </a>
                            <a class="share-btn share-btn-vk" href="whatsapp://send?text=<?= site_url('/?r=' . $user['id']) ?>" rel="nofollow" target="_blank">
                                <i class="fab fa-whatsapp"></i> <span>WhatsApp</span>
                            </a>
                        </div>
                    </div>

                    <div class="tab-pane fade" id="refbann" role="tabpanel" aria-labelledby="refbann-tab">
                        <h4 class="ref-card-title"><span class="ref-icon cyan"><i class="fas fa-image"></i></span> Banners</h4>

                        <ul class="nav nav-tabs" role="tablist">
                            <li class="nav-item" role="presentation"><a class="nav-link" href="#banner-728x90" aria-controls="banner-728x90" role="tab" data-toggle="tab">728x90</a></li>
                            <li class="nav-item" role="presentation"><a class="nav-link" href="#banner-468x60" aria-controls="banner-468x60" role="tab" data-toggle="tab">468x60</a></li>
                            <li class="nav-item" role="presentation"><a class="nav-link" href="#banner-320x100" aria-controls="banner-320x100" role="tab" data-toggle="tab">320x100</a></li>
                            <li class="nav-item" role="presentation"><a class="nav-link active" href="#banner-300x250" aria-controls="banner-300x250" role="tab" data-toggle="tab">300x250</a></li>
                        </ul>

                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane text-center" id="banner-728x90">
                                <p></p>
                                <a href="<?= site_url('/?r=' . $user['id']) ?>"><img src="https://coinlycash.com/img/banner/728x90.png" title="Make Money From <?= $settings['name'] ?>"></a>
                                <p></p>
                                <textarea class="form-control ref-textarea" rows="4" readonly="">&lt;!-- Start of banner code --&gt;
&lt;a href="<?= site_url('/?r=' . $user['id']) ?>"&gt;&lt;img src="https://coinlycash.com/img/banner/728x90.png" title="Make Money From <?= $settings['name'] ?>" /&gt;&lt;/a&gt;
&lt;!-- End of banner code --&gt;
                                </textarea>
                            </div>
                            <div role="tabpanel" class="tab-pane text-center" id="banner-468x60">
                                <p></p>
                                <a href="<?= site_url('/?r=' . $user['id']) ?>"><img src="https://coinlycash.com/img/banner/468x60.png" title="Make Money From <?= $settings['name'] ?>"></a>
                                <p></p>
                                <textarea class="form-control ref-textarea" rows="4" readonly="">&lt;!-- Start of banner code --&gt;
&lt;a href="<?= site_url('/?r=' . $user['id']) ?>"&gt;&lt;img src="https://coinlycash.com/img/banner/468x60.png" title="Make Money From <?= $settings['name'] ?>" /&gt;&lt;/a&gt;
&lt;!-- End of banner code --&gt;
                                </textarea>
                            </div>
                            <div role="tabpanel" class="tab-pane text-center" id="banner-320x100">
                                <p></p>
                                <a href="<?= site_url('/?r=' . $user['id']) ?>"><img src="https://coinlycash.com/img/banner/320x100.png" title="Make Money From <?= $settings['name'] ?>"></a>
                                <p></p>
                                <textarea class="form-control ref-textarea" rows="4" readonly="">&lt;!-- Start of banner code --&gt;
&lt;a href="<?= site_url('/?r=' . $user['id']) ?>"&gt;&lt;img src="https://coinlycash.com/img/banner/320x100.png" title="Make Money From <?= $settings['name'] ?>" /&gt;&lt;/a&gt;
&lt;!-- End of banner code --&gt;
                                </textarea>
                            </div>
                            <div role="tabpanel" class="tab-pane text-center active" id="banner-300x250">
                                <p></p>
                                <a href="<?= site_url('/?r=' . $user['id']) ?>"><img src="https://coinlycash.com/img/banner/300x250.png" title="Make Money From <?= $settings['name'] ?>"></a>
                                <p></p>
                                <textarea class="form-control ref-textarea" rows="4" readonly="">&lt;!-- Start of banner code --&gt;
&lt;a href="<?= site_url('/?r=' . $user['id']) ?>"&gt;&lt;img src="https://coinlycash.com/img/banner/300x250.png" title="Make Money From <?= $settings['name'] ?>" /&gt;&lt;/a&gt;
&lt;!-- End of banner code --&gt;
                                </textarea>
                            </div>
                        </div>
                    </div>

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

    <div class="col-lg-12">
        <div class="card ref-card acc-emerald">
            <div class="card-body">
                <h4 class="ref-card-title" style="justify-content:center;"><span class="ref-icon emerald"><i class="fas fa-users"></i></span> My Referrals</h4>

                <div class="table-responsive mt-3" style="max-height:500px;">
                    <?php if (count($referrals) > 0) { ?>
                        <table class="table ref-table text-center">
                            <thead>
                                <tr>
                                    <th scope="col">Username</th>
                                    <th scope="col">Last active</th>
                                    <th scope="col">Total earned</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                foreach ($referrals as $referral) {
                                    echo '<tr><th scope="row" class="username-rank">' . $referral["username"] . '</th><td>' . timespan($referral["last_active"], time(), 2) . ' ago</td><td><span class="ref-earned">' . format_money($referral["total_earned"]) . '</span></td></tr>';
                                }
                                ?>
                            </tbody>
                        </table>
                    <?php } else { ?>
                        <div class="ref-empty">
                            <i class="fas fa-user-plus"></i>
                            No referrals yet — share your link above to start earning.
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>

</div>

<center><div class="holidAds"></div></center>
<br>

<script>
function copyRefLink(){
    var input = document.getElementById('refLinkInput');
    input.select();
    input.setSelectionRange(0, 99999);
    navigator.clipboard && navigator.clipboard.writeText(input.value).catch(function(){
        document.execCommand('copy');
    });
    var btn = event.currentTarget;
    var original = btn.innerHTML;
    btn.innerHTML = '<i class="fas fa-check"></i> Copied';
    setTimeout(function(){ btn.innerHTML = original; }, 1500);
}
</script>