/* =================================================================
   My Desktop CertVault — certificate.css
   Certificate visual + print/PDF/PNG styles.

   Design goals:
   1. Use the four Google colors (#4285F4, #DB4437, #F4B400, #0F9D58)
      as a coherent palette so the certificate matches the site header
      and the brand mark.
   2. Keep the certificate on a single A4-landscape page when exported
      to PDF (locked via aspect-ratio: 1123/794).
   3. Support TWO signature blocks side-by-side, each loaded from a
      per-row file name in /branding/signatures/ (or ONE signature —
      the footer rebalances automatically).
   4. Support all 17 certificate types: the shared frame (header /
      issued-by / footer) plus a per-type middle section (.cert-body)
      that may include a From-To period box, a score box, and optional
      detail chips.
   5. Overflow safety: every text element is clamped (max-height +
      overflow:hidden) so long data can NEVER overlap neighbouring
      elements or the signature footer on the fixed 1123 × 794 canvas.
   ================================================================= */

/* ---- Frame that holds the certificate on the verify page ---- */
.certificate-frame {
  /* A4 landscape at 96dpi = 1123 x 794 px. */
  max-width: 1123px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- Certificate card ---- */
.certificate {
  position: relative;
  border-radius: 18px;
  /* 4-color stripe border, drawn as the element background (the white
     inner panel sits on top via ::before, leaving only 3px of stripe
     visible as the frame). */
  padding: 3px;
  box-shadow: 0 24px 60px rgba(66, 133, 244, 0.16);
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1123 / 794;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(135deg,
      var(--g-blue)   0%, var(--g-blue)   25%,
      var(--g-red)    25%, var(--g-red)    50%,
      var(--g-yellow) 50%, var(--g-yellow) 75%,
      var(--g-green)  75%, var(--g-green) 100%);
}

/* White inner panel that sits inside the 4-color border */
.certificate::before {
  content: "";
  position: absolute;
  inset: 3px;
  background:
    radial-gradient(circle at top right, rgba(244, 180, 0, 0.05), transparent 42%),
    radial-gradient(circle at bottom left, rgba(15, 157, 88, 0.05), transparent 42%),
    linear-gradient(135deg, #ffffff 0%, #f6f9ff 100%);
  border-radius: 16px;
  z-index: 0;
  pointer-events: none;
}

/* Decorative corner ornaments — drawn in the 4 colors, one per corner */
.certificate::after {
  content: "";
  position: absolute;
  inset: 14px;
  pointer-events: none;
  z-index: 1;
  border-radius: 12px;
  background:
    linear-gradient(to right,  var(--g-blue)   0 36px, transparent 36px) top left/36px 3px no-repeat,
    linear-gradient(to bottom, var(--g-blue)   0 36px, transparent 36px) top left/3px 36px no-repeat,
    linear-gradient(to left,   var(--g-red)    0 36px, transparent 36px) top right/36px 3px no-repeat,
    linear-gradient(to bottom, var(--g-red)    0 36px, transparent 36px) top right/3px 36px no-repeat,
    linear-gradient(to left,   var(--g-yellow) 0 36px, transparent 36px) bottom right/36px 3px no-repeat,
    linear-gradient(to top,    var(--g-yellow) 0 36px, transparent 36px) bottom right/3px 36px no-repeat,
    linear-gradient(to right,  var(--g-green)  0 36px, transparent 36px) bottom left/36px 3px no-repeat,
    linear-gradient(to top,    var(--g-green)  0 36px, transparent 36px) bottom left/3px 36px no-repeat;
  opacity: 0.85;
}

.certificate-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
  padding: 28px 64px 24px;
  min-height: 0;
}

/* ---- Header ---- */
.cert-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.cert-logo {
  /* Logo on a clean white rounded tile so a transparent PNG is fully
     visible (no 4-color gradient bleeding through). */
  height: 58px;
  width: 58px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 12px;
  padding: 6px;
  border: 1px solid var(--line);
}
.cert-id-badge {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: rgba(66, 133, 244, 0.10);
  padding: 7px 14px;
  border-radius: 999px;
  letter-spacing: 0.06em;
  border: 1px solid rgba(66, 133, 244, 0.20);
}

/* =================================================================
   MIDDLE SECTION — .cert-body
   Everything between the header and the "Issued on" block.
   Fills the available height and keeps its content centred; every
   child is clamped so the section can never overflow the page.
   ================================================================= */
.cert-body {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  overflow: hidden;
}

/* Safe centering: auto margins center the stack when it fits, but
   collapse to zero when it overflows — so any clipping (extreme data
   after compact + tight) always hits the description at the bottom,
   never the title at the top. */
.cert-body > :first-child { margin-top: auto; }
.cert-body > :last-child  { margin-bottom: auto; }

/* ---- Compact mode (auto-applied by render.js when content is tall) ---- */
.cert-body-compact { gap: 5px; }
.cert-body-compact .cert-title      { font-size: 40px; }
.cert-body-compact .cert-title-sm   { font-size: 34px; }
.cert-body-compact .cert-title-xs   { font-size: 30px; }
.cert-body-compact .cert-subtitle   { font-size: 14px; }
.cert-body-compact .cert-recipient  { font-size: 36px; line-height: 40px; max-height: 86px; }
.cert-body-compact .cert-award-value { font-size: 24px; line-height: 30px; max-height: 60px; }
.cert-body-compact .cert-meta-line  { font-size: 13px; }
.cert-body-compact .cert-period-box,
.cert-body-compact .cert-score-box  { padding: 7px 20px 8px; }
.cert-body-compact .cert-section-label,
.cert-body-compact .cert-score-heading { margin-bottom: 3px; }
.cert-body-compact .cert-details     { max-height: 52px; }
.cert-body-compact .cert-detail-row  { font-size: 11.5px; padding: 2px 10px; }
.cert-body-compact .cert-description { max-height: 40px; }

/* ---- Tight mode (auto-applied for extreme data) ---- */
.cert-body-tight { gap: 3px; }
.cert-body-tight .cert-eyebrow     { font-size: 11px; }
.cert-body-tight .cert-title       { font-size: 34px; }
.cert-body-tight .cert-title-sm    { font-size: 30px; }
.cert-body-tight .cert-title-xs    { font-size: 27px; }
.cert-body-tight .cert-subtitle    { font-size: 13px; }
.cert-body-tight .cert-recipient   { font-size: 32px; line-height: 36px; max-height: 78px; }
.cert-body-tight .cert-recipient-line { width: 300px; }
.cert-body-tight .cert-award-line  { font-size: 14px; }
.cert-body-tight .cert-award-value { font-size: 21px; line-height: 26px; max-height: 52px; }
.cert-body-tight .cert-meta-line   { font-size: 12.5px; }
.cert-body-tight .cert-period-box,
.cert-body-tight .cert-score-box   { padding: 5px 16px 6px; }
.cert-body-tight .cert-title-block { gap: 2px; }
.cert-body-tight .cert-period-cell { min-width: 96px; }
.cert-body-tight .cert-score-col   { min-width: 76px; padding: 0 14px; }
.cert-body-tight .cert-period-cell b { font-size: 15px; }
.cert-body-tight .cert-score-col b   { font-size: 15px; }
.cert-body-tight .cert-details      { max-height: 28px; }  /* one row of chips */
.cert-body-tight .cert-detail-row   { font-size: 11px; padding: 2px 9px; }
.cert-body-tight .cert-description  { font-size: 12px; line-height: 18px; max-height: 36px; }

/* ---- Title block ---- */
.cert-title-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  max-width: 100%;
}
.cert-eyebrow {
  font-size: 13px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--g-red);
  font-weight: 700;
  max-width: 96%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cert-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 46px;
  margin: 0;
  color: var(--primary-strong);
  letter-spacing: 0.02em;
  line-height: 1.05;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cert-title.cert-title-sm { font-size: 40px; }   /* titles 31–42 chars   */
.cert-title.cert-title-xs { font-size: 34px; }   /* titles longer than 42 */
.cert-subtitle {
  font-size: 15px;
  color: var(--text-soft);
  margin: 2px 0 0;
  font-style: italic;
}

/* ---- Recipient block ---- */
.cert-recipient-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  max-width: 100%;
}
.cert-recipient {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 42px;
  color: var(--text);
  line-height: 46px;
  padding: 0 36px 6px;
  text-align: center;
  max-width: 100%;
  max-height: 98px;          /* ≤ 2 lines (46×2 + 6px padding) */
  overflow: hidden;
}
.cert-recipient-line {
  width: 360px;
  max-width: 70%;
  height: 3px;
  background: linear-gradient(90deg,
      var(--g-blue), var(--g-red), var(--g-yellow), var(--g-green));
  border-radius: 2px;
}

/* ---- Award sentence + value ---- */
.cert-award-line {
  font-size: 15.5px;
  color: var(--text);
  max-width: 94%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.cert-award-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 27px;
  color: var(--primary-strong);
  font-style: italic;
  line-height: 34px;
  max-width: 88%;
  max-height: 68px;          /* ≤ 2 lines */
  overflow: hidden;
  flex-shrink: 0;
}

/* ---- Meta lines (small italic lines under the value) ---- */
.cert-meta-lines {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  max-width: 92%;
}
.cert-meta-line {
  font-size: 14px;
  color: var(--text-soft);
  font-style: italic;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Period box + Score box (share one row) ---- */
.cert-sections-row {
  display: flex;
  gap: 16px;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  flex-shrink: 0;
  min-height: 0;
}

.cert-section-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 5px;
  white-space: nowrap;
}

/* From / To box (internship, workshop, training, project, event…) */
.cert-period-box {
  border: 1px solid rgba(66, 133, 244, 0.28);
  background: rgba(66, 133, 244, 0.05);
  border-radius: 12px;
  padding: 9px 24px 10px;
  max-width: 48%;
}
.cert-period-grid {
  display: flex;
  gap: 30px;
  justify-content: center;
}
.cert-period-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 104px;
}
.cert-period-cell span {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.cert-period-cell b {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16.5px;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

/* Score / Grade / Result box (course-score, competition, project…) */
.cert-score-box {
  border: 1px solid rgba(15, 157, 88, 0.30);
  background: rgba(15, 157, 88, 0.05);
  border-radius: 12px;
  padding: 9px 6px 10px;
  max-width: 48%;
  overflow: hidden;
}
.cert-score-heading {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 5px;
  white-space: nowrap;
  text-align: center;
}
.cert-score-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.cert-score-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 18px;
  min-width: 86px;
  border-left: 1px solid rgba(15, 157, 88, 0.20);
}
.cert-score-col:first-child { border-left: none; }
.cert-score-col span {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.cert-score-col b {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  color: var(--g-green);
  font-weight: 700;
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Detail chips (Topic, Speaker, Department, Role …) ---- */
.cert-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  justify-content: center;
  max-width: 94%;
  max-height: 58px;          /* ≤ 2 rows of chips */
  overflow: hidden;
  flex-shrink: 0;
}
.cert-detail-row {
  font-size: 12.5px;
  color: var(--text-soft);
  background: rgba(66, 133, 244, 0.07);
  border: 1px solid rgba(66, 133, 244, 0.16);
  padding: 3px 12px;
  border-radius: 999px;
  line-height: 1.4;
  max-width: 460px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cert-detail-row b {
  color: var(--text);
  font-weight: 600;
}

/* ---- Description paragraph ---- */
.cert-description {
  max-width: 78%;
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--text-soft);
  font-style: italic;
  max-height: 40px;          /* ≤ 2 lines */
  overflow: hidden;
  flex-shrink: 0;
}

/* ---- Issued-by block ---- */
.cert-issued-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin-top: 4px;
  flex-shrink: 0;
}
.cert-issued-date {
  font-size: 13px;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.cert-issued-block .cert-issuer-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  color: var(--text);
  font-weight: 700;
}
.cert-issued-block .cert-issuer-title {
  font-size: 13px;
  color: var(--text-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---- Footer with two signatures + centered QR ---- */
.cert-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 24px;
  width: 100%;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* Keep the QR centred even when one signature block is hidden */
.cert-footer .cert-qr-wrap { grid-column: 2; }
.cert-footer.no-right { grid-template-columns: 1fr auto 1fr; }
.cert-footer.no-left  { grid-template-columns: 1fr auto 1fr; }

.cert-signature-block {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 92px;
  justify-content: flex-end;
}
.cert-signature-block.left  { align-items: flex-start; text-align: left;  }
.cert-signature-block.right { align-items: flex-end;   text-align: right; }

.cert-signature {
  height: 44px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  margin-bottom: 2px;
  filter: opacity(0.92);
}
.cert-signature-line {
  width: 80%;
  height: 1px;
  background: var(--text-soft);
  opacity: 0.5;
  margin: 4px 0 4px;
}
.cert-signature-block.left  .cert-signature-line { background: var(--g-blue);  opacity: 0.7; }
.cert-signature-block.right .cert-signature-line { background: var(--g-green); opacity: 0.7; }

/* Person name + designation under each signature (overrides the
   issuer-name / issuer-title rules above by being more specific) */
.cert-signature-block .cert-issuer-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}
.cert-signature-block .cert-issuer-title {
  font-size: 11px;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  text-transform: none;
}

.cert-qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.cert-qr {
  width: 78px; height: 78px;
  background: white;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.cert-qr-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft);
}

/* ---- Print / PDF ----
   The certificate element is locked to A4-landscape aspect ratio
   via `aspect-ratio: 1123/794`, and html2canvas is configured to
   render at the element's natural size, so the PDF always lands on
   exactly one A4-landscape page. */
@media print {
  body { background: white !important; }
  .site-header, .button-row, .site-shell::before { display: none !important; }
  .certificate-frame { padding: 0; max-width: none; }
  .certificate {
    box-shadow: none;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  @page { size: A4 landscape; margin: 0; }
}

/* ---- Loading state ---- */
.cert-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 16px;
  color: var(--text-soft);
}
