/* ══════════════════════════════════════════════════
   AOA Merit Certificate — background-image approach
   ══════════════════════════════════════════════════ */

/* ─── Overlay & modal shell ─── */
.cert-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    display: none; align-items: center; justify-content: center;
    padding: 40px 20px; overflow-y: auto;
}
.cert-overlay.open { display: flex; }

/* cert-mount is the flex child of the overlay — give it full width so the
   modal inside can actually grow (otherwise it shrinks to content size). */
#cert-mount { width: 100%; display: flex; justify-content: center; }

.cert-modal { width: 100%; max-width: 960px; margin: auto; }

.cert-toolbar {
    display: flex; justify-content: flex-end;
    gap: 12px; margin-bottom: 16px;
}
.cert-toolbar button {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 12px 22px; border-radius: 50px; cursor: pointer;
    font-size: 13px; font-weight: 700; border: none;
    font-family: "Inter", sans-serif; transition: all 0.2s;
}
.cert-print { background: #c5a059; color: #fff; }
.cert-print:hover { background: #b08d44; }
.cert-close { background: rgba(255,255,255,0.9); color: #1b4d3e; }
.cert-close:hover { background: #fff; }

/* ─── Certificate card ─── */
#certificate {
    position: relative;
    width: 100%;
    /* fallback aspect ratio; overridden inline per-template once the image loads */
    aspect-ratio: 3512 / 2484;
    background-position: center;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-color: #fff;
    box-shadow: 0 40px 80px -20px rgba(0,0,0,0.6);
    overflow: hidden;
    /* makes 1cqw == 1% of the certificate's own width, so text below
       scales WITH the certificate — identical on screen and in print */
    container-type: inline-size;
}

/* ─── Overlaid text fields ─── */
/* Positioned by their CENTRE point (top/left % + this transform). All other
   styling (font, size, weight, color, alignment) is set inline per field
   from the admin-configured certificate template. */
.cert-field {
    position: absolute;
    transform: translate(-50%, -50%);
    line-height: 1.2;
    white-space: nowrap;
}

/* ─── "No certificate yet" state ─── */
.cert-unavailable {
    background: #fff;
    border-radius: 16px;
    padding: 60px 30px;
    text-align: center;
    color: var(--text-muted, #64748b);
}
.cert-unavailable i {
    font-size: 2.5rem;
    color: var(--accent, #c5a059);
    margin-bottom: 16px;
    display: block;
}
.cert-unavailable p { font-size: 1rem; margin: 0; }

/* ─── Print ─── */
@media print {
    @page { size: A4 landscape; margin: 0; }
    html, body {
        margin: 0 !important; padding: 0 !important;
        width: 100% !important; height: 100% !important;
        background: #fff !important;
    }
    body > *:not(.cert-overlay) { display: none !important; }
    .cert-overlay {
        position: absolute !important; top: 0 !important; left: 0 !important;
        width: 100% !important; height: 100% !important;
        display: block !important; padding: 0 !important; margin: 0 !important;
        background: #fff !important; backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important; overflow: hidden !important;
    }
    #cert-mount { width: 100%; height: 100%; }
    .cert-toolbar { display: none !important; }
    .cert-modal {
        max-width: none !important; width: 100% !important;
        height: 100% !important; margin: 0 !important; padding: 0 !important;
    }
    #certificate {
        box-sizing: border-box !important; box-shadow: none !important;
        width: 100% !important; height: 100% !important;
        aspect-ratio: auto !important; margin: 0 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
}
