/* Certificates: builder, template cards, viewer, verification, print. Uses the academy theme variables. */

/* ---------- the certificate artwork itself (shared by every screen) ---------- */
.cert-page { position: relative; overflow: hidden; box-sizing: border-box; background: #fff; color: #111; flex: none; text-align: left; -webkit-font-smoothing: antialiased; }
.cert-el { position: absolute; box-sizing: border-box; user-select: none; -webkit-user-select: none; }
.cert-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.cert-empty { display: grid !important; place-items: center; border: 1px dashed #94a3b8; color: #64748b; font: 12px/1.3 Inter, sans-serif; text-align: center; padding: 4px; background: rgba(148, 163, 184, .08); }
.cert-hidden { opacity: .25 !important; }

/* ---------- admin: sub navigation, template cards ---------- */
.cert-nav { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 18px; padding: 0; }
.cert-nav a { display: inline-block; padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; color: var(--text); font-weight: 600; font-size: .9rem; }
.cert-nav a[aria-current='page'], .cert-nav a:hover { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.cert-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.cert-card { border: 1px solid var(--border); border-radius: var(--radius, 12px); background: var(--surface, #fff); overflow: hidden; display: flex; flex-direction: column; }
.cert-thumb { position: relative; background: #e5e7eb; width: 100%; overflow: hidden; border-bottom: 1px solid var(--border); }
.cert-card-body { padding: 12px 14px; display: grid; gap: 6px; flex: 1; }
.cert-card-body h3 { margin: 0; font-size: 1.02rem; }
.cert-card-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 14px; }
.cert-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.cert-stats > div { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface, #fff); }
.cert-stats strong { display: block; font-size: 1.6rem; line-height: 1.1; color: var(--primary); }
.cert-bad { color: var(--danger, #c0392b); }
.cert-pick { display: block; cursor: pointer; }
.cert-pick input { position: absolute; opacity: 0; }
.cert-pick:has(input:checked) .cert-card, .cert-pick input:focus-visible + .cert-card { outline: 3px solid var(--primary); }

/* ---------- student cards ---------- */
.cert-mine { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.cert-mine .cert-card .cm-media { aspect-ratio: 16 / 9; background: var(--bg-soft); overflow: hidden; }
.cert-mine .cm-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cm-ph { display: grid; place-items: center; height: 100%; color: var(--text-muted); }

/* ---------- viewer ---------- */
.cert-view-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cert-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cert-stage { position: relative; width: 100%; max-width: 1123px; margin: 0 auto; box-shadow: 0 10px 40px rgba(0, 0, 0, .18); border-radius: 4px; overflow: hidden; background: #fff; }
.cert-congrats { text-align: center; border: 1px solid var(--border); border-radius: 16px; padding: 22px 16px; margin-bottom: 18px; background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 9%, var(--bg)), var(--bg)); }
.cert-congrats h2 { margin: 6px 0; font-size: clamp(1.3rem, 4vw, 1.9rem); }
.cert-confetti { font-size: 2.2rem; animation: cert-pop .7s cubic-bezier(.2, 1.4, .3, 1); display: inline-block; }
@keyframes cert-pop { from { transform: scale(.3) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }
#cert-print-host { display: none; }
@media (prefers-reduced-motion: reduce) { .cert-confetti { animation: none; } }

/* ---------- verification ---------- */
.vf-wrap { max-width: 920px; margin: 0 auto; }
.vf-search { display: flex; flex-wrap: wrap; gap: 8px; }
.vf-search input { flex: 1 1 240px; min-height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem; }
.vf-result { border-radius: 16px; padding: 20px; border: 2px solid var(--ok, #16a34a); background: color-mix(in srgb, var(--ok, #16a34a) 7%, var(--bg)); margin-top: 18px; }
.vf-result.is-revoked { border-color: var(--danger, #c0392b); background: color-mix(in srgb, var(--danger, #c0392b) 7%, var(--bg)); }
.vf-result.is-none { border-color: var(--border); background: var(--bg-soft); }
.vf-title { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; font-weight: 800; margin: 0 0 12px; }
.vf-dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 20px; margin: 0; }
.vf-dl dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.vf-dl dd { margin: 2px 0 0; font-weight: 700; word-break: break-word; }

/* ---------- builder ---------- */
body.cb-body { overflow: hidden; }
body.cb-body .ah, body.cb-body .ah-top, body.cb-body .af, body.cb-body footer { display: none !important; }
body.cb-body main#main { padding: 0; }
.cb { position: fixed; inset: 0; z-index: 100; display: grid; grid-template-rows: 54px 1fr; grid-template-columns: 270px 1fr 300px; grid-template-areas: 'top top top' 'left stage right'; background: var(--bg-soft, #f3f4f6); color: var(--text); font-size: 14px; }
.cb-top { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--bg); border-bottom: 1px solid var(--border); overflow-x: auto; white-space: nowrap; }
.cb-top .sp { flex: 1; min-width: 8px; }
.cb-top input[type='text'] { height: 34px; border-radius: 8px; border: 1px solid var(--border); padding: 0 10px; min-width: 200px; background: var(--bg); color: var(--text); font-weight: 700; }
.cb-status { font-size: .8rem; color: var(--text-muted); min-width: 120px; }
.cb-status.is-ok { color: var(--ok, #16a34a); } .cb-status.is-bad { color: var(--danger, #c0392b); } .cb-status.is-saving { color: var(--primary); }
.cb .btn.is-on { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.cb .btn:disabled { opacity: .4; cursor: default; }
.cb-left, .cb-right { background: var(--bg); overflow-y: auto; padding: 10px; }
.cb-left { grid-area: left; border-inline-end: 1px solid var(--border); }
.cb-right { grid-area: right; border-inline-start: 1px solid var(--border); }
.cb-tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.cb-tabs button { flex: 1; padding: 7px 4px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-weight: 700; cursor: pointer; }
.cb-tabs button.is-on { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.cb-group h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin: 12px 0 6px; }
.cb-items { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cb-item { padding: 8px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: .8rem; text-align: center; cursor: grab; line-height: 1.2; }
.cb-item:hover, .cb-item:focus-visible { border-color: var(--primary); color: var(--primary); }
.cb-stage { grid-area: stage; overflow: auto; padding: 32px; display: grid; place-items: start center; }
.cb-pagebox { position: relative; box-shadow: 0 8px 40px rgba(0, 0, 0, .25); background: #fff; flex: none; touch-action: none; }
.cb-pagebox .cert-el:not(.cert-hidden) { cursor: move; }
.cb-pagebox .cert-el:hover { outline: 1px dashed var(--primary); outline-offset: 1px; }
.is-preview .cb-pagebox .cert-el { cursor: default; } .is-preview .cb-pagebox .cert-el:hover { outline: 0; }
.cb-grid { background-image: linear-gradient(rgba(0, 0, 0, .06) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, .06) 1px, transparent 1px) !important; background-size: 10px 10px; }
.cb-overlay, .cb-guides { position: absolute; inset: 0; pointer-events: none; }
.cb-sel { position: absolute; border: calc(1.5px / var(--z, 1)) solid var(--primary); box-sizing: border-box; pointer-events: none; }
.cb-sel.is-locked { border-style: dashed; border-color: #f59e0b; }
.cb-h { position: absolute; width: calc(11px / var(--z, 1)); height: calc(11px / var(--z, 1)); margin: calc(-5.5px / var(--z, 1)); background: #fff; border: calc(1.5px / var(--z, 1)) solid var(--primary); border-radius: 2px; pointer-events: auto; }
.cb-h-nw { left: 0; top: 0; cursor: nwse-resize; } .cb-h-n { left: 50%; top: 0; cursor: ns-resize; } .cb-h-ne { left: 100%; top: 0; cursor: nesw-resize; }
.cb-h-e { left: 100%; top: 50%; cursor: ew-resize; } .cb-h-se { left: 100%; top: 100%; cursor: nwse-resize; } .cb-h-s { left: 50%; top: 100%; cursor: ns-resize; }
.cb-h-sw { left: 0; top: 100%; cursor: nesw-resize; } .cb-h-w { left: 0; top: 50%; cursor: ew-resize; }
.cb-rot { left: 50%; top: calc(-26px / var(--z, 1)); border-radius: 50%; cursor: grab; background: var(--primary); }
.cb-guide { position: absolute; background: #ec4899; }
.cb-guide-v { top: 0; bottom: 0; width: calc(1px / var(--z, 1)); } .cb-guide-h { left: 0; right: 0; height: calc(1px / var(--z, 1)); }
.cb-f { display: grid; gap: 3px; margin-bottom: 8px; font-size: .78rem; font-weight: 600; color: var(--text-muted); }
.cb-f input, .cb-f select, .cb-f textarea { width: 100%; min-height: 32px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-weight: 500; }
.cb-f input[type='color'] { padding: 2px; height: 34px; }
.cb-f textarea { resize: vertical; }
.cb-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.cb-inline { display: flex; gap: 8px; align-items: center; }
.cb-btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.cb-tools { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.cb-tool { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; }
.cb-tool:hover, .cb-tool:focus-visible { border-color: var(--primary); color: var(--primary); }
.cb-empty { padding: 24px 6px; text-align: center; }
.cb-layer { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border: 1px solid transparent; border-radius: 8px; margin-bottom: 3px; background: var(--bg-soft); }
.cb-layer.is-sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.cb-layer.is-off .cb-layer-name { opacity: .5; text-decoration: line-through; }
.cb-layer-name { flex: 1; text-align: start; border: 0; background: transparent; color: var(--text); cursor: pointer; font: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-layer-tools button { border: 0; background: transparent; cursor: pointer; padding: 3px 4px; color: var(--text); }
.cb-modal { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; background: rgba(0, 0, 0, .55); padding: 16px; }
.cb-modal[hidden] { display: none; }
.cb-modal-card { background: var(--bg); border-radius: 14px; padding: 16px; width: min(720px, 100%); max-height: 86vh; overflow: auto; }
.cb-assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.cb-asset { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 8px; background: repeating-conic-gradient(#e5e7eb 0 25%, #fff 0 50%) 0 0 / 14px 14px; padding: 4px; cursor: pointer; }
.cb-asset img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cb button:focus-visible, .cb input:focus-visible, .cb select:focus-visible, .cb textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.cb-narrow { display: none; }
@media (max-width: 1100px) { .cb { grid-template-columns: 220px 1fr 250px; } }
@media (max-width: 860px) { .cb { display: none; } .cb-narrow { display: block; padding: 40px 20px; text-align: center; } body.cb-body { overflow: auto; } }

/* ---------- print: only the certificate ---------- */
@media print {
    body.cert-view-page > *:not(#cert-print-host) { display: none !important; }
    body.cert-view-page, body.cert-view-page main { background: #fff !important; margin: 0 !important; padding: 0 !important; }
    #cert-print-host { display: block !important; position: absolute; left: 0; top: 0; }
    #cert-print-host .cert-page { transform: none !important; box-shadow: none; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
