/**
 * Certificate Document — A4 landscape, professional brand identity.
 *
 * Bassmah palette: brand #2f5aae, cyan #0891b2, green #27ae60, gold #c9982f
 */

:root {
    --cert-brand:       #1e3a6f;  /* deeper navy for prestige */
    --cert-brand-dark:  #0f2547;
    --cert-cyan:        #0c4a6e;
    --cert-green:       #15803d;
    --cert-gold:        #b08527;  /* richer antique gold */
    --cert-gold-light:  #d4a83a;
    --cert-cream:       #faf7ed;  /* parchment-like background tint */
    --cert-text:        #0f172a;
    --cert-body:        #334155;
    --cert-muted:       #64748b;
    --cert-line:        #e2e8f0;
}

/* Hide site chrome on the certificate page */
body.single-certificate .main-header,
body.single-certificate header.main-header,
body.single-certificate .global-footer,
body.single-certificate footer:not(.cert-footer),
body.single-certificate .ap-side-nav,
body.single-certificate .floating-whatsapp,
body.single-certificate .floating-buttons {
    display: none !important;
}
body.single-certificate {
    background: #e5e7eb;
    font-family: 'Tajawal', 'Cairo', sans-serif;
    color: var(--cert-text);
    margin: 0;
    padding: 0;
}
body.single-certificate .site-content {
    padding: 0 !important;
    margin: 0 !important;
}

/* ===== Top control bar ===== */
.cert-controls {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--cert-line);
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.06);
}
.cert-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border-radius: 999px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.cert-btn--primary {
    background: linear-gradient(135deg, var(--cert-brand), var(--cert-cyan));
    color: #fff;
    box-shadow: 0 8px 20px rgba(47, 90, 174, 0.35);
}
.cert-btn--primary:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(47, 90, 174, 0.5); }
.cert-controls__type {
    margin-inline-start: auto;
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    background: var(--cert-gold);
}

/* ===== Document container =====
   Allows horizontal scroll on viewports narrower than A4 landscape so the
   page always renders at its true 297×210mm proportions (matching PDF). */
.cert-doc {
    padding: 30px 20px 50px;
    overflow-x: auto;
    overflow-y: visible;
}
.cert-doc::-webkit-scrollbar { height: 8px; }
.cert-doc::-webkit-scrollbar-thumb { background: rgba(15,23,42,0.2); border-radius: 4px; }

/* ===== A4 LANDSCAPE Page (297×210mm) — fixed dimensions always ===== */
.cert-page {
    width: 297mm;
    height: 210mm;       /* fixed, not min-height — prevents overflow */
    max-height: 210mm;
    margin: 0 auto;
    flex-shrink: 0;
    background:#fff;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
    padding: 10mm;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

/* ===== Decorative triple-line frame ===== */
.cert-frame {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}
/* Outermost subtle gold edge */
.cert-frame--outer {
    inset: 6mm;
    border: 1px solid var(--cert-gold);
    border-radius: 2px;
    opacity: 0.6;
}
/* Bold navy main frame */
.cert-frame--inner {
    inset: 9mm;
    border: 4px double var(--cert-brand);
    border-radius: 3px;
}
/* Inner thin gold line for refinement */
.cert-page::before {
    content: "";
    position: absolute;
    inset: 13mm;
    border: 1px solid var(--cert-gold);
    border-radius: 2px;
    opacity: 0.5;
    pointer-events: none;
    z-index: 1;
}

/* Corner medallions — proper ornamental flourishes via SVG-style geometry */
.cert-corner {
    position: absolute;
    width: 28mm;
    height: 28mm;
    pointer-events: none;
    z-index: 3;
}
/* Each corner has 3 layered ornaments: corner triangle + diagonal line + diamond */
.cert-corner::before,
.cert-corner::after {
    content: "";
    position: absolute;
    pointer-events: none;
}
/* Filled triangular corner accent */
.cert-corner::before {
    top: 0;
    left: 0;
    width: 18mm;
    height: 18mm;
    background: linear-gradient(135deg, var(--cert-brand) 0%, var(--cert-brand) 30%, transparent 30.5%);
    clip-path: polygon(0 0, 100% 0, 0 100%);
}
/* Gold accent diamond + line */
.cert-corner::after {
    top: 12mm;
    left: 12mm;
    width: 8mm;
    height: 8mm;
    background:
        linear-gradient(45deg, transparent 45%, var(--cert-gold) 45%, var(--cert-gold) 55%, transparent 55%),
        linear-gradient(-45deg, transparent 45%, var(--cert-gold) 45%, var(--cert-gold) 55%, transparent 55%);
}

.cert-corner--tl { top: 6mm;    left: 6mm;    transform: rotate(0deg); }
.cert-corner--tr { top: 6mm;    right: 6mm;   transform: rotate(90deg); }
.cert-corner--bl { bottom: 6mm; left: 6mm;    transform: rotate(-90deg); }
.cert-corner--br { bottom: 6mm; right: 6mm;   transform: rotate(180deg); }

/* ===== Watermark — full center, very faint ===== */
.cert-watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}
.cert-watermark img {
    width: 60%;
    max-width: 380px;
    opacity: 0.05;
    filter: grayscale(100%);
    mix-blend-mode: multiply;
}

/* ===== Inner content wrapper — tight to fit one A4 landscape page ===== */
.cert-page__inner {
    position: relative;
    z-index: 5;
    width: 100%;
    height: 100%;
    padding: 12mm 16mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* ===== Top bar (cert number + date) ===== */
.cert-topbar {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--cert-muted);
    margin-bottom: 3mm;
    padding: 0 4mm;
    letter-spacing: 0.3px;
}
.cert-topbar strong {
    color: var(--cert-brand);
    font-weight: 800;
    font-family: 'Cairo', 'Tajawal', sans-serif;
}

/* ===== Brand header (logos) ===== */
.cert-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 3mm;
}
.cert-brand__logo {
    height: 50px;
    width: auto;
    object-fit: contain;
}
.cert-brand__logo--academy {
    height: 44px;
}
.cert-brand__divider {
    display: inline-block;
    width: 1.5px;
    height: 36px;
    background: linear-gradient(180deg, transparent, var(--cert-gold) 30%, var(--cert-gold) 70%, transparent);
}

/* ===== Title block ===== */
.cert-titlewrap {
    text-align: center;
    margin-bottom: 5mm;
    position: relative;
}
.cert-title-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 18px;
    background: linear-gradient(135deg, var(--cert-gold), #8a6a1f);
    color: #fffdf5;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2px;
    border-radius: 999px;
    margin-bottom: 8px;
    box-shadow: 0 3px 8px rgba(176, 133, 39, 0.25);
    border: 1px solid var(--cert-gold-light);
}
.cert-title-eyebrow::before,
.cert-title-eyebrow::after {
    content: "❖";
    color: var(--cert-gold-light);
    font-size: 9px;
    opacity: 0.9;
}
.cert-title {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 26px;
    font-weight: 900;
    color: var(--cert-brand);
    margin: 0 0 6px;
    line-height: 1.2;
    text-shadow: 0 1px 0 rgba(176, 133, 39, 0.06);
}
.cert-title-ribbon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.cert-title-ribbon__line {
    flex: 0 1 80px;
    height: 1.5px;
    background: linear-gradient(90deg, transparent, var(--cert-gold), transparent);
}
.cert-title-ribbon__diamond {
    color: var(--cert-gold);
    font-size: 11px;
}

/* ===== Body content ===== */
.cert-body {
    flex: 1;
    text-align: center;
    color: var(--cert-body);
    line-height: 1.7;
    font-size: 13px;
}
.cert-intro {
    margin: 0 0 4px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--cert-body);
}

/* Trainee name */
.cert-trainee-name {
    position: relative;
    margin: 6px auto 10px;
    padding: 4px 36px 8px;
    display: inline-block;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 28px;
    font-weight: 900;
    color: var(--cert-brand);
    line-height: 1.15;
    text-shadow: 0 1px 0 rgba(176, 133, 39, 0.06);
}
.cert-trainee-name::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 90%;
    height: 5px;
    background:
        linear-gradient(180deg, var(--cert-gold) 0, var(--cert-gold) 1px, transparent 1px, transparent 3px, var(--cert-gold) 3px, var(--cert-gold) 4px, transparent 4px);
}
.cert-trainee-name::before {
    content: "❦";
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--cert-cream);
    padding: 0 10px;
    color: var(--cert-gold);
    font-size: 14px;
    line-height: 1;
}

.cert-body-text {
    margin: 6px auto 8px;
    max-width: 230mm;
    font-size: 12.5px;
    line-height: 1.75;
    font-weight: 500;
    color: var(--cert-body);
}
.cert-closing {
    margin: 4px auto 6px;
    max-width: 230mm;
    font-size: 11.5px;
    line-height: 1.7;
    color: var(--cert-muted);
}
.cert-issuer {
    display: inline-block;
    margin: 6px 0 0;
    padding: 3px 22px;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 14.5px;
    font-weight: 900;
    color: var(--cert-brand);
    border-top: 1.5px solid var(--cert-gold);
    border-bottom: 1.5px solid var(--cert-gold);
    letter-spacing: 0.3px;
}

/* ===== Footer (signature + QR + ornamental seal) ===== */
.cert-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-top: 4mm;
    padding-top: 4mm;
    position: relative;
}
/* Decorative divider above the footer */
.cert-footer::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 50%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--cert-gold) 30%, var(--cert-gold) 70%, transparent);
    opacity: 0.6;
}
.cert-sign,
.cert-stamp {
    flex: 1 1 0;
    text-align: center;
}
.cert-sign__img {
    display: block;
    margin: 0 auto 6px;
    max-width: 140px;
    max-height: 50px;
    object-fit: contain;
}
.cert-sign__line {
    display: block;
    width: 70%;
    margin: 0 auto 6px;
    border-top: 1.5px solid var(--cert-brand);
    height: 24px;
    position: relative;
}
.cert-sign__line::after {
    content: "✑";
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--cert-cream);
    padding: 0 6px;
    color: var(--cert-gold);
    font-size: 12px;
}
.cert-sign__name {
    display: block;
    font-size: 12.5px;
    font-weight: 900;
    color: var(--cert-text);
    font-family: 'Cairo', 'Tajawal', sans-serif;
}
.cert-sign__title {
    display: block;
    font-size: 10.5px;
    color: var(--cert-muted);
    margin-top: 2px;
    letter-spacing: 0.4px;
}

/* QR — refined */
.cert-qr {
    flex: 0 0 auto;
    width: 65px;
    height: 65px;
    background: #fff;
    border: 1.5px solid var(--cert-gold);
    border-radius: 5px;
    padding: 3px;
    box-shadow: 0 2px 6px rgba(176, 133, 39, 0.18);
}
.cert-qr img,
.cert-qr canvas { width: 100%; height: 100%; }

/* Stamp area */
.cert-stamp {
    display: flex;
    align-items: center;
    justify-content: center;
}
.cert-stamp img {
    max-width: 110px;
    max-height: 90px;
    object-fit: contain;
}
/* Ornamental seal placeholder when no stamp uploaded */
.cert-stamp--placeholder {
    position: relative;
    width: 75px;
    height: 75px;
    border-radius: 50%;
    border: 2px solid var(--cert-gold);
    background:
        radial-gradient(circle at center, var(--cert-cream) 0%, var(--cert-cream) 60%, transparent 60%),
        repeating-conic-gradient(var(--cert-gold) 0deg 4deg, transparent 4deg 12deg);
    color: var(--cert-brand);
    font-size: 9px;
    font-weight: 800;
    text-align: center;
    line-height: 1.3;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    box-shadow: 0 2px 6px rgba(176, 133, 39, 0.2);
}
.cert-stamp--placeholder::before {
    content: "✦";
    display: block;
    font-size: 15px;
    color: var(--cert-gold);
    margin-bottom: 1px;
}
.cert-stamp img {
    max-width: 90px;
    max-height: 75px;
    object-fit: contain;
}

/* ============= PRINT ============= */
@media print {
    *, *::before, *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    body.single-certificate {
        background: #fff;
        margin: 0;
    }
    .cert-controls,
    .global-header,
    .global-footer,
    header,
    footer:not(.cert-footer) {
        display: none !important;
    }
    .cert-doc {
        padding: 0 !important;
        margin: 0 !important;
    }
    .cert-page {
        box-shadow: none !important;
        margin: 0 !important;
        page-break-after: auto;
        break-after: auto;
    }
    @page {
        size: A4 landscape;
        margin: 0;
    }
}

/* ============= Responsive — controls bar only.
       The certificate page itself stays at fixed A4 landscape (297×210mm)
       so the on-screen preview always matches the downloaded PDF exactly.
       On viewports narrower than that, the .cert-doc wrapper scrolls. ============= */
@media (max-width: 760px) {
    .cert-controls {
        flex-wrap: wrap;
    }
    .cert-controls__type {
        margin-inline-start: 0;
        order: -1;
        width: 100%;
        text-align: center;
    }
}
