/* ── Certificate Viewer Modal Styles ── */

.cm-cert-modal-overlay {
  position: fixed;
  width: 100%;
  height: 100%;
  inset: 0;
  /* top: 0;
  left: 0;
  right: 0;
  bottom: 0; */
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cm-cert-modal-overlay.active {
  display: flex;
  opacity: 1;
}

.cm-cert-modal-content {
  background: #e8e6fa;
  border-radius: 12px;
  width: 100%;
  max-width: 1000px;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  position: relative;
  font-family: 'Cormorant Garamond', Georgia, serif;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cm-cert-modal-overlay.active .cm-cert-modal-content {
  transform: translateY(0);
}

.cm-cert-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  z-index: 10;
}

.cm-cert-modal-title {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
}

.cm-cert-modal-actions {
  display: flex;
  gap: 12px;
}

.cm-cert-modal-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cm-cert-modal-btn-print {
  background: #4e34ed;
  color: #ffffff;
}

.cm-cert-modal-btn-print:hover {
  background: #3d26c0;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(78, 52, 237, 0.25);
}

.cm-cert-modal-btn-close {
  background: #f1f5f9;
  color: #475569;
}

.cm-cert-modal-btn-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.cm-cert-modal-body {
  padding: 30px;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  background: #e8e6fa;
}

.cm-cert-loading {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.9);
  padding: 20px 40px;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  font-family: 'DM Mono', monospace;
  color: #4e34ed;
  z-index: 20;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.cm-cert-loading.active {
  display: flex;
}

.cm-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #ddd8fc;
  border-top-color: #4e34ed;
  border-radius: 50%;
  animation: cm-spin 1s linear infinite;
}

@keyframes cm-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Certificate Internal Styles (From Template) ── */
.cm-cert-wrap {
  width: 100%;
  max-width: 920px;
  aspect-ratio: 1.414 / 1;
  position: relative;
  /* Hide until loaded if needed, or keep visible structure */
}

.cm-cert {
  width: 100%;
  height: 100%;
  background: #ffffff;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  box-shadow: 0 12px 60px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .08);
}

/* Outer decorative border */
.cm-cert::before {
  content: '';
  position: absolute;
  inset: 14px;
  border: 1.5px solid #c5baf8;
  pointer-events: none;
  z-index: 1;
}

/* Inner thin border */
.cm-cert::after {
  content: '';
  position: absolute;
  inset: 19px;
  border: 0.5px solid #ddd8fc;
  pointer-events: none;
  z-index: 1;
}

/* Subtle watermark background */
/* .cm-cert-wrap::before {
  content: 'TOEFL';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  font-family: 'Cinzel', serif;
  font-size: 120px;
  font-weight: 700;
  color: rgba(78, 52, 237, 0.035);
  pointer-events: none;
  z-index: 0;
  white-space: nowrap;
  letter-spacing: 12px;
} */

/* ── Top bar ── */
.cm-cert-top-bar {
  background: linear-gradient(135deg, #4e34ed 0%, #6a50f5 60%, #3d26c0 100%);
  padding: 14px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}

.cm-ets-logo-area {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.cm-vls-logo {
  width: clamp(28px, 3.5vw, 44px);
  height: clamp(28px, 3.5vw, 44px);
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: .92;
}

.cm-ets-badge {
  font-family: 'Cinzel', serif;
  font-size: clamp(14px, 2.2vw, 22px);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 4px;
  line-height: 1;
}

.cm-ets-label {
  font-family: 'DM Mono', monospace;
  font-size: clamp(6px, .8vw, 9px);
  color: rgba(255, 255, 255, .65);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 3px;
}

.cm-toefl-logo-area {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.cm-toefl-wordmark {
  font-family: 'Cinzel', serif;
  font-size: clamp(20px, 3.5vw, 38px);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 5px;
  line-height: 1;
}

.cm-toefl-super {
  font-size: 0.45em;
  vertical-align: super;
}

.cm-toefl-tagline {
  font-family: 'DM Mono', monospace;
  font-size: clamp(7px, 1vw, 11px);
  color: rgba(255, 255, 255, .75);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── Corner ornaments ── */
.cm-corner {
  position: absolute;
  width: 44px;
  height: 44px;
  z-index: 3;
  color: #c5baf8;
}

.cm-corner svg {
  width: 100%;
  height: 100%;
}

.cm-corner-tl {
  top: 24px;
  left: 24px;
}

.cm-corner-tr {
  top: 24px;
  right: 24px;
  transform: scaleX(-1);
}

.cm-corner-bl {
  bottom: 24px;
  left: 24px;
  transform: scaleY(-1);
}

.cm-corner-br {
  bottom: 24px;
  right: 24px;
  transform: scale(-1);
}

/* ── Certificate content ── */
.cm-cert-content {
  position: relative;
  z-index: 2;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 72px 14px;
  gap: 10px;
}

/* Header block */
.cm-cert-header-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.cm-cert-title-line {
  font-family: 'Cinzel', serif;
  font-size: clamp(14px, 2.2vw, 24px);
  font-weight: 700;
  color: #4e34ed;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.cm-cert-presented {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(9px, 1.1vw, 12px);
  color: #7a8aaa;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-style: italic;
}

.cm-cert-name {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(22px, 4vw, 46px);
  font-weight: 300;
  text-transform: capitalize;
  font-style: italic;
  color: #2a1c8a;
  line-height: 1.1;
  margin: 4px 0;
  text-shadow: 1px 1px 0 rgba(78, 52, 237, .08);
}

.cm-cert-exam-name {
  font-family: 'Cinzel', serif;
  font-size: clamp(8px, 1.1vw, 12px);
  color: #5540c0;
  letter-spacing: 1.5px;
  margin-top: 2px;
}

/* ── Divider ── */
.cm-cert-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.cm-cert-divider::before,
.cm-cert-divider::after {
  content: '';
  flex: 1;
  max-width: 140px;
  height: 1px;
  background: linear-gradient(90deg, transparent, #c5baf8);
}

.cm-cert-divider::after {
  background: linear-gradient(90deg, #c5baf8, transparent);
}

.cm-cert-divider span {
  color: #4e34ed;
  font-size: 12px;
  opacity: .6;
}

/* ── Score Panel ── */
.cm-score-panel {
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
  background: linear-gradient(135deg, #f2f0ff 0%, #ece8fd 100%);
  border: 1px solid #c5baf8;
  border-radius: 10px;
  padding: 14px 20px;
}

.cm-total-score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  flex-shrink: 0;
}

.cm-score-label {
  font-family: 'DM Mono', monospace;
  font-size: clamp(6px, .8vw, 8px);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #6a7aaa;
}

.cm-score-value {
  font-family: 'Cinzel', serif;
  font-size: clamp(30px, 5vw, 56px);
  font-weight: 700;
  color: #4e34ed;
  line-height: 1;
}

.cm-score-scale {
  font-family: 'DM Mono', monospace;
  font-size: clamp(6px, .75vw, 8px);
  color: #8a9abb;
  letter-spacing: 1px;
}

.cm-score-divider-v {
  width: 1px;
  height: 70px;
  background: #c5baf8;
  flex-shrink: 0;
}

.cm-skill-scores {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cm-skill-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-skill-name {
  font-family: 'DM Mono', monospace;
  font-size: clamp(7px, .85vw, 9px);
  color: #5a48a0;
  letter-spacing: 1px;
  width: 52px;
  flex-shrink: 0;
  text-align: right;
}

.cm-skill-bar-wrap {
  flex: 1;
  height: 5px;
  background: #ddd8fc;
  border-radius: 10px;
  overflow: hidden;
}

.cm-skill-bar {
  height: 100%;
  width: var(--cm-score-w, 0%);
  background: linear-gradient(90deg, #7a64f8, #4e34ed);
  border-radius: 10px;
  transition: width 1s ease-out;
}

.cm-skill-score {
  font-family: 'DM Mono', monospace;
  font-size: clamp(7px, .9vw, 10px);
  color: #4e34ed;
  font-weight: 500;
  width: 20px;
  text-align: center;
}

/* ── Meta info ── */
.cm-cert-meta {
  display: flex;
  justify-content: center;
  gap: 32px;
  width: 100%;
}

.cm-meta-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cm-meta-label {
  font-family: 'DM Mono', monospace;
  font-size: clamp(6px, .75vw, 8px);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #8a9abb;
}

.cm-meta-value {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(10px, 1.2vw, 13px);
  color: #2a1c8a;
  font-weight: 600;
}

.cm-meta-value.mono {
  font-family: 'DM Mono', monospace;
  font-size: clamp(7px, .9vw, 11px);
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.95;
}

/* ── QR Code area ── */
.cm-cert-qr-area {
  position: absolute;
  bottom: 32px;
  right: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 3;
}

.cm-cert-qr-area .cm-qr-logo {
  position: absolute;
  left: 50%;
  top: calc(50% - 5px);
  width: 28px;
  height: 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: translate(-50%, -50%);
  background-color: #fff;
  border-radius: 2px;
}

.cm-cert-qr-area .cm-qr-logo img {
  max-width: 24px;
  height: auto;
  margin-left: auto;
  margin-right: auto;
  display: block;
}

#cm-cert-qr-container {
  border: 3px solid #c5baf8;
  border-radius: 6px;
  padding: 4px;
  background: #fff;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wp-admin.toefl-management_page_toefl-certificates #cm-cert-qr-container {
  width: 70px;
  height: 70px;
}

#cm-cert-qr-container img,
#cm-cert-qr-container canvas {
  width: 72px !important;
  height: 72px !important;
  display: block;
}

.cm-qr-label {
  font-family: 'DM Mono', monospace;
  font-size: 7px;
  letter-spacing: 1.5px;
  line-height: 1;
  text-transform: uppercase;
  color: #9aabb0;
}

/* ── Print Styles ── */
@media print {
  @page {
    size: A4 portrait;
    top: 0;
    margin: 0;
  }

  body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Hide everything in the body unconditionally */
  body>* {
    display: none !important;
  }

  /* Show only our modal container and make it full screen */
  #cm-cert-viewer-modal {
    display: block !important;
    position: absolute !important;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    backdrop-filter: none !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* Make sure all children of the modal are visible */
  #cm-cert-viewer-modal * {
    visibility: visible;
  }

  .cm-cert-modal-content {
    box-shadow: none !important;
    transform: none !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 auto !important;
    height: 100vh !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .cm-cert-modal-header,
  .cm-cert-loading {
    display: none !important;
  }

  .cm-cert-modal-body {
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Lock dimensions for the certificate wrap (A4 landscape is roughly 297mm x 210mm) */
  .cm-cert-wrap {
    width: 210mm !important;
    height: 148mm !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    margin: auto !important;
    page-break-inside: avoid !important;
    transform: scale(0.96);
    /* Slight scale down to ensure it prevents edge cropping */
    transform-origin: center center;
  }

  .cm-cert {
    box-shadow: none !important;
    width: 100% !important;
    height: 100% !important;
  }

  /* Inner thin border */
  .cm-cert::after {
    border: 0.5px solid #ddd8fc !important;
  }

  /* Outer decorative border */
  .cm-cert::before {
    border: 1.5px solid #c5baf8 !important;
  }

  .cm-cert-content {
    border: 1px solid #7a64f8 !important;
    border-top-width: 0 !important;
  }

  .cm-cert-content .cm-cert-presented,
  .cm-cert-content .cm-cert-exam-name {
    color: #2a1c8a !important;
  }

  /* Force backgrounds and gradients to print */
  .cm-cert-top-bar {
    max-width: 100% !important;
    background-color: #3d26c0 !important;
    background-image: linear-gradient(135deg, #4e34ed 0%, #6a50f5 60%, #3d26c0 100%) !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-top-bar .cm-toefl-wordmark,
  .cm-cert-top-bar .cm-toefl-super,
  .cm-cert-top-bar .cm-ets-badge,
  .cm-cert-top-bar .cm-ets-label {
    color: #fff !important;
  }

  .cm-skill-bar-wrap {
    background-color: #ddd8fc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-skill-bar {
    background-color: #7a64f8 !important;
    background-image: linear-gradient(90deg, #7a64f8, #4e34ed) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Preserve Score Panel Background */
  .cm-score-panel {
    background: #f2f0ff !important;
    background-image: linear-gradient(135deg, #f2f0ff 0%, #ece8fd 100%) !important;
    border: 1px solid #c5baf8 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Prevent Flex/Grid Breakage */
  .cm-skill-scores {
    display: flex !important;
    flex-direction: column !important;
  }

  .cm-score-divider-v {
    background: #c5baf8 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-qr-area {
    bottom: 32px !important;
    right: 36px !important;
    transform: none !important;
    display: flex !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-presented,
  .cm-cert-exam-name {
    color: #7a8aaa !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-name {
    color: #2a1c8a !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-divider::before {
    background: linear-gradient(90deg, transparent, #c5baf8) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-divider::after {
    background: linear-gradient(90deg, #c5baf8, transparent) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-score-label,
  .cm-score-scale,
  .cm-meta-label,
  .cm-qr-label {
    color: #6a7aaa !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-total-score-block .cm-score-value,
  .cm-skill-row .cm-skill-score,
  .cm-skill-row .cm-skill-name,
  .cm-cert-title-line {
    color: #4e34ed !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cm-cert-wrap .cm-qr-logo {
    background-color: #fff !important;
  }
}

/* ── Mobile Responsive ── */
@media screen and (max-width: 768px) {
  .cm-cert-modal-overlay {
    padding: 10px;
  }

  .cm-cert-modal-body {
    padding: 15px;
  }

  .cm-cert-content {
    padding: 12px 32px 10px;
  }

  .cm-score-panel {
    flex-direction: column;
    gap: 12px;
  }

  .cm-score-divider-v {
    width: 80px;
    height: 1px;
  }

  .cm-cert-qr-area {
    display: none;
  }
}