<!DOCTYPE html>
<html>
<head>
<title>Member Card</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>

<style>
body{
    margin:0;
    font-family:'Segoe UI', sans-serif;
    background:#0f172a;
    display:flex;
    flex-direction:column;
    align-items:center;
    padding:30px 10px;
}

/* ðŸ”¥ FIX SIZE KTA */
.card{
    width:380px;
    height:220px;
    border-radius:18px;
    padding:18px;
    color:white;
    position:relative;

    background: linear-gradient(135deg,#1e3a8a,#2563eb,#3b82f6);
    box-shadow:0 15px 40px rgba(0,0,0,0.4);
}

/* HEADER */
.header{
    display:flex;
    justify-content:space-between;
    align-items:center;
}

/* LOGO */
.logo img{
    height:26px;
}

/* STATUS */
.status{
    padding:4px 10px;
    border-radius:20px;
    font-size:10px;
    font-weight:bold;
    background: <?= $status_color ?>;
}

/* CONTENT */
.content{
    display:flex;
    margin-top:12px;
}

/* FOTO */
.profile img{
    width:70px;
    height:90px;
    border-radius:8px;
    object-fit:cover;
    border:2px solid rgba(255,255,255,0.4);
}

/* INFO GRID (ðŸ”¥ FIX RAPI) */
.info{
    margin-left:12px;
    display:grid;
    grid-template-columns:80px auto;
    row-gap:4px;
    column-gap:5px;
    align-items:center;

    padding-right:70px; /* 🔥 SPACE UNTUK QR */
}

/* LABEL */
.label{
    font-size:11px;
    opacity:0.7;
}

/* VALUE */
.value{
    font-size:13px;
    font-weight:500;
}

/* MEMBER ID */
.member-id{
    position:absolute;
    bottom:12px;
    left:18px;
    font-size:10px;
}

/* QR */
.qr{
    position:absolute;
    bottom:12px;
    right:12px;
}

.qr canvas{
    background:white;
    padding:3px;
    border-radius:6px;
    width:65px !important;
    height:65px !important;
}

.value{
    font-size:13px;
    font-weight:500;

    max-width:180px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

/* BUTTON */
.actions{
    margin-top:15px;
    text-align:center;
}

button{
    padding:10px 15px;
    border:none;
    border-radius:8px;
    margin:5px;
    cursor:pointer;
}

.btn-download{
    background:#10b981;
    color:white;
}

.btn-print{
    background:#2563eb;
    color:white;
}

/* MOBILE */
@media(max-width:400px){
    .card{
        transform:scale(0.95);
    }
}
</style>
</head>

<body>

<div id="card" class="card">

    <div class="header">
        <div class="logo">
            <img src="/membership/public/assets/img/logo.png">
        </div>
        <div class="status"><?= $status_label ?></div>
    </div>

    <div class="content">

        <div class="profile">
            <img src="/membership/public/assets/uploads/<?= $foto ?>">
        </div>

        <div class="info">
            <div class="label">Nama</div>
            <div class="value"><?= $nama ?></div>

            <div class="label">Role</div>
            <div class="value"><?= $role ?></div>

            <div class="label">Perusahaan</div>
            <div class="value"><?= $perusahaan ?></div>
        </div>

    </div>

    <div class="member-id">
        <?= $member_code ?>
    </div>

    <div class="qr">
        <canvas id="qrcode"></canvas>
    </div>

</div>

<div class="actions">
    <button class="btn-download" onclick="downloadCard()">Download PNG</button>
    <button class="btn-print" onclick="window.print()">Print / PDF</button>
</div>

<script>
const url = window.location.href;

QRCode.toCanvas(document.getElementById('qrcode'), url, { width:90 });

/* ðŸ”¥ FIX DOWNLOAD (LEBIH STABIL) */
function downloadCard(){
    html2canvas(document.getElementById("card"), {
        scale:2
    }).then(canvas=>{
        const link = document.createElement("a");
        link.download = "member-card.png";
        link.href = canvas.toDataURL("image/png");
        link.click();
    });
}
</script>

</body>
</html>