@import url("https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&display=swap");

* {
  box-sizing: border-box;
}

:root {
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --secondary: #7c3a96;
  --secondary-light: #b99bd1;
  --gold: #c8a25a;
  --gold-soft: rgba(200, 162, 90, 0.22);
  --paper: #fffdf9;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #b91c1c;
}

body {
  margin: 0;
  font-family: "Cairo", Tahoma, Arial, sans-serif;
  background: #f3f4f6;
  color: var(--text);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.screen {
  width: min(520px, calc(100vw - 32px));
  margin: 60px auto;
}

.card {
  background: #fff;
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.card h1 {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 28px;
}

.card p {
  line-height: 1.8;
}

.example-links {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.example-links a {
  display: block;
  direction: ltr;
  text-decoration: none;
  background: #ecfdf5;
  color: var(--primary);
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 14px;
  padding: 12px;
  font-weight: bold;
}

.login-logo {
  width: 170px;
  height: auto;
  margin-bottom: 12px;
}

.login-form {
  text-align: right;
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

label {
  display: block;
  font-weight: bold;
  margin: 14px 0 7px;
  font-size: 14px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 11px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  background: #fff;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.8;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(0.98);
}

.login-form button,
.print-btn {
  background: var(--primary);
  color: #fff;
}

.clear-btn {
  background: #e5e7eb;
  color: #374151;
}

.logout-btn {
  margin-top: 12px;
  width: 100%;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}

.error {
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 10px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

#certificateApp {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  padding: 24px;
  min-height: 100vh;
}

.controls {
  background: #ffffff;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  height: fit-content;
  position: sticky;
  top: 20px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e5e7eb;
}

.brand-line img {
  width: 76px;
  height: auto;
}

.brand-line h1 {
  margin: 0;
  font-size: 22px;
  color: var(--primary);
}

.brand-line p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.preview-area {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding-bottom: 24px;
}

/* Luxury certificate template */
.certificate {
  width: 1123px;
  min-height: 794px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.98) 30%, rgba(255, 255, 255, 0.98) 70%, rgba(255, 255, 255, 0.88)),
    radial-gradient(circle at 72% 18%, rgba(124, 58, 150, 0.08), transparent 27%),
    radial-gradient(circle at 23% 70%, rgba(15, 118, 110, 0.08), transparent 32%),
    var(--paper);
  border: 5px solid var(--secondary);
  border-radius: 34px;
  padding: 46px 78px 44px 78px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.16);
}

.certificate::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(124, 58, 150, 0.35);
  border-radius: 27px;
  pointer-events: none;
  z-index: 1;
}

.certificate::after {
  content: "";
  position: absolute;
  inset: 35px 58px;
  border-top: 3px solid rgba(200, 162, 90, 0.26);
  border-bottom: 3px solid rgba(200, 162, 90, 0.26);
  pointer-events: none;
  z-index: 0;
}

/* Golden ornamental side strips */
.gold-side {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 76px;
  opacity: 0.6;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 20px, rgba(200, 162, 90, 0.45) 0 7px, transparent 8px),
    radial-gradient(circle at 22px 54px, rgba(200, 162, 90, 0.35) 0 6px, transparent 7px),
    radial-gradient(circle at 54px 88px, rgba(200, 162, 90, 0.35) 0 6px, transparent 7px),
    radial-gradient(ellipse at center, transparent 45%, rgba(200, 162, 90, 0.45) 46%, transparent 58%),
    repeating-linear-gradient(180deg, transparent 0 18px, rgba(200, 162, 90, 0.28) 19px 22px, transparent 23px 42px);
  background-size: 76px 120px, 76px 120px, 76px 120px, 76px 80px, 76px 90px;
}

.gold-side.left {
  right: 58px;
}

.gold-side.right {
  left: 58px;
}

/* Teal ribbon and badge similar to the sample */
.ribbon {
  position: absolute;
  top: 0;
  right: 150px;
  width: 110px;
  height: 365px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), transparent 35%, rgba(0, 0, 0, 0.08)),
    linear-gradient(180deg, #0b5f59, #1f8a80);
  z-index: 2;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

.ribbon::after {
  content: "";
  position: absolute;
  bottom: -1px;
  right: 0;
  border-right: 55px solid transparent;
  border-left: 55px solid transparent;
  border-top: 62px solid #fffdf9;
}

.ribbon-badge {
  position: absolute;
  top: 104px;
  right: 106px;
  width: 190px;
  height: 190px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fffdf7;
  border: 8px solid #8b5a2b;
  border-radius: 50%;
  box-shadow:
    0 0 0 5px #f4dfb5,
    0 8px 18px rgba(0, 0, 0, 0.18);
}

.ribbon-badge::before {
  content: "";
  position: absolute;
  inset: -16px;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg, #c8a25a 0deg 8deg, #f8e7bd 8deg 16deg);
  z-index: -1;
}

.ribbon-badge img {
  width: 145px;
  max-height: 120px;
  object-fit: contain;
}

.corner-ribbons {
  position: absolute;
  top: -20px;
  left: 0;
  width: 315px;
  height: 130px;
  z-index: 2;
  pointer-events: none;
}

.corner-ribbons::before,
.corner-ribbons::after {
  content: "";
  position: absolute;
  height: 46px;
  border-radius: 28px;
  background: linear-gradient(90deg, rgba(124, 58, 150, 0.58), rgba(184, 154, 208, 0.95));
  transform: rotate(-45deg);
  box-shadow: 0 9px 20px rgba(124, 58, 150, 0.18);
}

.corner-ribbons::before {
  width: 235px;
  top: 26px;
  left: 4px;
}

.corner-ribbons::after {
  width: 265px;
  top: 26px;
  left: 135px;
}

.cert-header,
.cert-body,
.cert-footer {
  position: relative;
  z-index: 3;
}

.cert-header {
  min-height: 128px;
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  align-items: start;
  gap: 18px;
}

.header-block {
  font-size: 17px;
  line-height: 1.7;
  font-weight: bold;
  color: #4b5563;
}

.header-block:first-child {
  padding-top: 12px;
  padding-right: 220px;
  min-width: 430px;
}

.header-block.left {
  text-align: left;
  padding-top: 18px;
  padding-left: 20px;
}

.main-logo {
  display: none;
}

.cert-body {
  text-align: center;
  padding-top: 4px;
  margin-right: 170px;
  margin-left: 30px;
}

.cert-body h2 {
  font-family: "Cairo", Tahoma, Arial, sans-serif;
  font-size: 58px;
  color: #111827;
  margin: 0 0 18px;
  font-weight: 700;
  letter-spacing: 0;
  text-shadow: 0 1px 0 #fff;
}

.grant-line {
  font-size: 24px;
  color: #6b3a86;
  margin: 10px 0 22px;
  font-weight: bold;
}

.recipient-name {
  display: inline-block;
  min-width: 530px;
  padding: 8px 28px 15px;
  border-bottom: 3px solid var(--gold);
  font-size: 42px;
  color: #111827;
  font-weight: bold;
  margin-bottom: 22px;
}

.message {
  max-width: 760px;
  margin: 0 auto;
  font-size: 24px;
  line-height: 2.05;
  color: #374151;
}

.cert-footer {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: end;
  gap: 24px;
  margin-top: 45px;
  margin-right: 150px;
  font-size: 19px;
}

.footer-box {
  min-height: 100px;
}

.footer-label {
  font-weight: bold;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

.stamp-box {
  text-align: center;
}

.school-logo-placeholder {
  width: 120px;
  height: 80px;
  border: 2px dashed rgba(15, 118, 110, 0.35);
  border-radius: 16px;
  margin: 8px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.45);
}

.school-logo-placeholder img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.signature-line {
  margin-top: 26px;
  border-top: 2px solid #6b7280;
  padding-top: 8px;
  min-width: 220px;
  display: inline-block;
}

.watermark {
  position: absolute;
  left: 46%;
  top: 54%;
  transform: translate(-50%, -50%);
  font-size: 150px;
  color: rgba(124, 58, 150, 0.035);
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
}

@media (max-width: 1000px) {
  #certificateApp {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }

  .preview-area {
    justify-content: flex-start;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  body {
    background: #fff;
  }

  .controls,
  .screen {
    display: none !important;
  }

  #certificateApp {
    display: block;
    padding: 0;
  }

  .preview-area {
    padding: 0;
    overflow: visible;
  }

  .certificate {
    width: 297mm;
    height: 210mm;
    min-height: 210mm;
    box-shadow: none;
    border-width: 4px;
    page-break-inside: avoid;
  }
}


/* Fixed image template mode
   ضع صورة القالب داخل:
   public/assets/templates/school-slug.jpg
   ثم أضف templateImage في إعدادات المدرسة.
*/
.certificate.image-template-mode {
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border: none;
  border-radius: 0;
  padding: 0;
}

.certificate.image-template-mode::before,
.certificate.image-template-mode::after,
.certificate.image-template-mode .gold-side,
.certificate.image-template-mode .ribbon,
.certificate.image-template-mode .ribbon-badge,
.certificate.image-template-mode .corner-ribbons,
.certificate.image-template-mode .watermark,
.certificate.image-template-mode .main-logo {
  display: none !important;
}

.certificate.image-template-mode .cert-header {
  display: none;
}

.certificate.image-template-mode.show-template-header .cert-header {
  display: grid;
  position: absolute;
  top: 36px;
  right: 70px;
  left: 70px;
  min-height: auto;
  z-index: 3;
}

.certificate.image-template-mode .cert-body {
  position: absolute;
  top: var(--body-top, 150px);
  right: var(--body-right, 180px);
  left: var(--body-left, 80px);
  margin: 0;
  padding: 0;
  text-align: center;
  z-index: 3;
}

.certificate.image-template-mode .cert-body h2 {
  font-size: var(--title-size, 52px);
  margin-bottom: 18px;
  color: #111827;
}

.certificate.image-template-mode.hide-template-title .cert-body h2 {
  display: none;
}

.certificate.image-template-mode .grant-line {
  font-size: 23px;
  margin: 8px 0 18px;
  color: #6b3a86;
}

.certificate.image-template-mode .recipient-name {
  font-size: var(--recipient-size, 42px);
  min-width: 450px;
  padding: 8px 22px 12px;
  margin-bottom: 18px;
  border-bottom: 3px solid rgba(124, 58, 150, 0.65);
}

.certificate.image-template-mode .message {
  max-width: 760px;
  font-size: var(--message-size, 23px);
  line-height: 2;
  color: #374151;
}

.certificate.image-template-mode .cert-footer {
  position: absolute;
  right: var(--footer-right, 160px);
  left: var(--footer-left, 70px);
  bottom: var(--footer-bottom, 58px);
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  z-index: 3;
  font-size: 18px;
}

.certificate.image-template-mode .school-logo-placeholder {
  background: rgba(255,255,255,0.45);
}


/* Alignment fixes for uploaded fixed image templates */
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 210px);
  right: var(--body-right, 80px);
  left: var(--body-left, 310px);
}

.certificate.image-template-mode .grant-line {
  font-size: 24px;
  margin: 0 0 18px;
  color: #6b3a86;
  font-weight: 800;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255,255,255,0.75);
}

.certificate.image-template-mode .recipient-name {
  font-size: var(--recipient-size, 42px);
  min-width: 420px;
  max-width: 620px;
  padding: 8px 22px 13px;
  margin-bottom: 18px;
  border-bottom: 3px solid rgba(124, 58, 150, 0.68);
  text-align: center;
}

.certificate.image-template-mode .message {
  max-width: 700px;
  font-size: var(--message-size, 23px);
  line-height: 2;
  text-align: center;
}

.certificate.image-template-mode .cert-footer {
  right: var(--footer-right, 40px);
  left: var(--footer-left, 130px);
  bottom: var(--footer-bottom, 58px);
  align-items: end;
}

.certificate.image-template-mode .footer-box {
  text-align: center;
}

.certificate.image-template-mode .signature-line {
  min-width: 210px;
}


/* Cairo font override */
.certificate,
.controls,
.card,
input,
textarea,
select,
button {
  font-family: "Cairo", Tahoma, Arial, sans-serif;
}

.certificate.image-template-mode .cert-body h2,
.cert-body h2,
.grant-line,
.recipient-name,
.message,
.footer-box {
  font-family: "Cairo", Tahoma, Arial, sans-serif;
}


/* Print background fix: template is a real image, not CSS background */
.certificate {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.template-image-layer {
  display: none;
}

.certificate.image-template-mode .template-image-layer.active {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}

.certificate.image-template-mode {
  background-image: none !important;
  background-color: #fff !important;
}

.certificate.image-template-mode .cert-body,
.certificate.image-template-mode .cert-footer,
.certificate.image-template-mode .cert-header {
  z-index: 3;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .certificate.image-template-mode .template-image-layer.active {
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: fill !important;
    z-index: 0 !important;
  }
}


/* Final alignment for fixed image certificate templates */
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 255px);
  right: var(--body-right, 90px);
  left: var(--body-left, 310px);
}

.certificate.image-template-mode .grant-line {
  font-size: var(--grant-size, 23px);
  margin: 0 0 18px;
  color: #6b3a86;
  font-weight: 800;
  text-align: center;
  line-height: 1.55;
}

.certificate.image-template-mode .recipient-name {
  font-size: var(--recipient-size, 42px);
  min-width: 410px;
  max-width: 620px;
  padding: 6px 22px 12px;
  margin-bottom: 18px;
  border-bottom: 3px solid rgba(124, 58, 150, 0.68);
}

.certificate.image-template-mode .message {
  max-width: 700px;
  font-size: var(--message-size, 23px);
  line-height: 1.9;
}

.certificate.image-template-mode .cert-footer {
  right: var(--footer-right, 55px);
  left: var(--footer-left, 125px);
  bottom: var(--footer-bottom, 48px);
  align-items: end;
}

.certificate.image-template-mode .footer-box {
  text-align: center;
}

.certificate.image-template-mode .footer-label {
  font-size: 18px;
}

.certificate.image-template-mode .signature-line {
  min-width: 210px;
}


/* Requested customizations */
.template-school-name {
  display: none;
}

.certificate.image-template-mode .template-school-name {
  display: block;
  position: absolute;
  top: 68px;
  right: 165px;
  z-index: 4;
  color: #0f766e;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.4;
  text-align: right;
  text-shadow: 0 1px 0 rgba(255,255,255,0.85);
}

.footer-label.empty-label {
  min-height: 28px;
  margin-bottom: 8px;
}

.school-logo-placeholder {
  border-style: dashed;
  color: transparent;
}

.school-logo-placeholder:empty::after {
  content: "";
}

.signature-line {
  display: none !important;
}

/* Cleaner footer in template mode */
.certificate.image-template-mode .school-logo-placeholder {
  border: none;
  background: transparent;
  width: 120px;
  height: 80px;
}

.certificate.image-template-mode .footer-box.stamp-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
}


/* Enhanced school header on certificate template */
.template-school-header {
  display: none;
}

.certificate.image-template-mode .template-school-header {
  display: block;
  position: absolute;
  top: 52px;
  right: 88px;
  z-index: 4;
  min-width: 260px;
  max-width: 390px;
  text-align: right;
  line-height: 1.5;
  text-shadow: 0 1px 0 rgba(255,255,255,0.9);
}

.certificate.image-template-mode .template-school-name {
  display: block;
  position: static;
  color: #0b5f59;
  font-size: 32px;
  font-weight: 900;
  line-height: 1.35;
}

.certificate.image-template-mode .template-education-dept {
  color: #7c3a96;
  font-size: 20px;
  font-weight: 800;
  margin-top: 2px;
}

@media print {
  .certificate.image-template-mode .template-school-header {
    display: block !important;
  }
}


/* Final official header placement fix */
.certificate.image-template-mode .template-school-header {
  display: block;
  position: absolute;
  top: 40px;
  right: 120px;
  z-index: 4;
  min-width: 260px;
  max-width: 360px;
  text-align: center;
  line-height: 1.45;
  text-shadow: 0 1px 0 rgba(255,255,255,0.92);
}

.certificate.image-template-mode .template-school-name {
  display: block;
  position: static;
  color: #111111;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.35;
  margin-top: 4px;
  text-align: center;
}

.certificate.image-template-mode .template-education-dept {
  color: #111111;
  font-size: 22px;
  font-weight: 800;
  margin-top: 0;
  text-align: center;
}

@media print {
  .certificate.image-template-mode .template-school-header {
    top: 40px !important;
    right: 120px !important;
    max-width: 360px !important;
    text-align: center !important;
  }

  .certificate.image-template-mode .template-school-name,
  .certificate.image-template-mode .template-education-dept {
    color: #111111 !important;
    text-align: center !important;
  }
}


/* Third line: school stage */
.certificate.image-template-mode .template-school-header {
  top: 36px;
  right: 120px;
  max-width: 380px;
}

.certificate.image-template-mode .template-education-dept {
  color: #111111;
  font-size: 21px;
  font-weight: 800;
  margin-top: 0;
  text-align: center;
}

.certificate.image-template-mode .template-school-name {
  color: #111111;
  font-size: 29px;
  font-weight: 800;
  line-height: 1.3;
  margin-top: 4px;
  text-align: center;
}

.certificate.image-template-mode .template-school-stage {
  color: #111111;
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
  text-align: center;
  line-height: 1.35;
}

@media print {
  .certificate.image-template-mode .template-school-stage {
    color: #111111 !important;
    text-align: center !important;
  }
}


/* Reviewed fixes after visual check */
.certificate.image-template-mode .template-school-header {
  top: 28px !important;
  right: 165px !important;
  max-width: 320px !important;
  min-width: 240px !important;
  text-align: center !important;
  line-height: 1.25 !important;
}

.certificate.image-template-mode .template-education-dept {
  color: #111111 !important;
  font-size: 18px !important;
  font-weight: 800 !important;
  margin-top: 0 !important;
  margin-bottom: 2px !important;
  text-align: center !important;
  white-space: normal !important;
}

.certificate.image-template-mode .template-school-name {
  color: #111111 !important;
  font-size: 26px !important;
  font-weight: 900 !important;
  line-height: 1.2 !important;
  margin-top: 0 !important;
  margin-bottom: 2px !important;
  text-align: center !important;
}

.certificate.image-template-mode .template-school-stage {
  color: #111111 !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  margin-top: 0 !important;
  text-align: center !important;
}

/* Improve general vertical balance a bit */
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 265px) !important;
}

.certificate.image-template-mode .message {
  max-width: 720px !important;
  line-height: 1.85 !important;
}

@media print {
  .certificate.image-template-mode .template-school-header {
    top: 28px !important;
    right: 165px !important;
    max-width: 320px !important;
  }
}


/* Precise layout fixes from annotated screenshot */
.certificate.image-template-mode .template-school-header {
  top: 138px !important;
  right: 88px !important;
  max-width: 300px !important;
  min-width: 260px !important;
  text-align: center !important;
  line-height: 1.25 !important;
  z-index: 4 !important;
}

.certificate.image-template-mode .template-education-dept {
  color: #111111 !important;
  font-size: 17px !important;
  font-weight: 800 !important;
  margin: 0 0 2px !important;
  text-align: center !important;
}

.certificate.image-template-mode .template-school-name {
  color: #111111 !important;
  font-size: 25px !important;
  font-weight: 900 !important;
  line-height: 1.18 !important;
  margin: 0 0 2px !important;
  text-align: center !important;
}

.certificate.image-template-mode .template-school-stage {
  color: #111111 !important;
  font-size: 15px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  margin: 0 !important;
  text-align: center !important;
}

/* Move main text slightly down from the title */
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 290px) !important;
  right: var(--body-right, 90px) !important;
  left: var(--body-left, 310px) !important;
}

.certificate.image-template-mode .grant-line {
  margin-bottom: 22px !important;
}

/* Lift footer items away from bottom border */
.certificate.image-template-mode .cert-footer {
  bottom: var(--footer-bottom, 76px) !important;
  right: var(--footer-right, 55px) !important;
  left: var(--footer-left, 125px) !important;
}

@media print {
  .certificate.image-template-mode .template-school-header {
    top: 138px !important;
    right: 88px !important;
    max-width: 300px !important;
  }

  .certificate.image-template-mode .cert-body {
    top: var(--body-top, 290px) !important;
  }

  .certificate.image-template-mode .cert-footer {
    bottom: var(--footer-bottom, 76px) !important;
  }
}


/* Green/gold certificate theme for the new templates */
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 258px) !important;
  right: var(--body-right, 90px) !important;
  left: var(--body-left, 310px) !important;
}

.certificate.image-template-mode .grant-line {
  font-size: var(--grant-size, 23px) !important;
  color: #0c6b61 !important;
  font-weight: 800 !important;
  margin: 0 0 14px !important;
  line-height: 1.6 !important;
  text-shadow: 0 1px 0 rgba(255,255,255,0.85);
}

.certificate.image-template-mode .recipient-name {
  font-size: var(--recipient-size, 42px) !important;
  color: #172033 !important;
  border-bottom: 3px solid #a970d6 !important;
  padding: 6px 22px 10px !important;
  margin-bottom: 16px !important;
}

.certificate.image-template-mode .message {
  max-width: 720px !important;
  font-size: var(--message-size, 23px) !important;
  color: #4b5563 !important;
  line-height: 1.85 !important;
}

.certificate.image-template-mode .footer-label {
  color: #0c6b61 !important;
  font-weight: 800 !important;
}

.certificate.image-template-mode .cert-footer {
  bottom: var(--footer-bottom, 76px) !important;
  right: var(--footer-right, 55px) !important;
  left: var(--footer-left, 125px) !important;
}

@media print {
  .certificate.image-template-mode .cert-body {
    top: var(--body-top, 258px) !important;
  }
}


/* Final requested adjustments:
   - raise the main content block a little
   - make the middle underline green instead of purple
*/
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 238px) !important;
}

.certificate.image-template-mode .grant-line {
  margin: 0 0 12px !important;
}

.certificate.image-template-mode .recipient-name {
  border-bottom: 3px solid #0c6b61 !important;
  margin-bottom: 14px !important;
}

.certificate.image-template-mode .message {
  margin-top: 0 !important;
}


/* Dimension tuning / balance adjustments */
.certificate.image-template-mode .cert-body {
  top: var(--body-top, 226px) !important;
  right: var(--body-right, 95px) !important;
  left: var(--body-left, 320px) !important;
}

.certificate.image-template-mode .grant-line {
  max-width: 760px !important;
  margin: 0 auto 14px !important;
  font-size: var(--grant-size, 22px) !important;
  line-height: 1.55 !important;
}

.certificate.image-template-mode .recipient-name {
  min-width: 420px !important;
  max-width: 560px !important;
  padding: 6px 18px 10px !important;
  margin-bottom: 16px !important;
}

.certificate.image-template-mode .message {
  max-width: 760px !important;
  margin: 0 auto !important;
  font-size: var(--message-size, 22px) !important;
  line-height: 1.75 !important;
}

.certificate.image-template-mode .cert-footer {
  bottom: var(--footer-bottom, 88px) !important;
  right: var(--footer-right, 65px) !important;
  left: var(--footer-left, 135px) !important;
}

.certificate.image-template-mode .footer-box {
  min-height: 78px !important;
}

@media print {
  .certificate.image-template-mode .cert-body {
    top: var(--body-top, 226px) !important;
    right: var(--body-right, 95px) !important;
    left: var(--body-left, 320px) !important;
  }

  .certificate.image-template-mode .cert-footer {
    bottom: var(--footer-bottom, 88px) !important;
    right: var(--footer-right, 65px) !important;
    left: var(--footer-left, 135px) !important;
  }
}


/* Slightly lower the grant sentence only */
.certificate.image-template-mode .grant-line {
  margin-top: 10px !important;
  margin-bottom: 14px !important;
}


/* Final fix:
   1) Lower the sentence "تتشرف المدرسة بمنح هذه الشهادة..."
      more clearly than before.
   2) Make the principal name bold.
*/
.certificate.image-template-mode .grant-line {
  margin-top: 26px !important;
  margin-bottom: 16px !important;
}

#previewPrincipalName {
  font-weight: 800 !important;
}


/* Final requested tuning:
   1) Make school name the same size as education department and school stage.
   2) Lower the sentence "تتشرف المدرسة..."
   3) Raise the student name, underline, and the appreciation message slightly.
*/
.certificate.image-template-mode .template-education-dept,
.certificate.image-template-mode .template-school-name,
.certificate.image-template-mode .template-school-stage {
  font-size: 18px !important;
  line-height: 1.25 !important;
}

.certificate.image-template-mode .template-school-name {
  font-weight: 800 !important;
}

.certificate.image-template-mode .grant-line {
  margin-top: 22px !important;
  margin-bottom: 6px !important;
}

.certificate.image-template-mode .recipient-name {
  margin-top: -10px !important;
  margin-bottom: 10px !important;
  border-bottom: 3px solid #0c6b61 !important;
}

.certificate.image-template-mode .message {
  margin-top: -4px !important;
}


/* Performance tuning */
.template-image-layer {
  will-change: opacity;
}

.certificate.image-template-mode .template-image-layer.active {
  image-rendering: auto;
}


/* Mobile preview fix:
   Scale the whole certificate as one piece on phones.
   Printing keeps the original A4 dimensions.
*/
@media screen and (max-width: 1099px) {
  .preview-area {
    align-items: flex-start !important;
    justify-content: center !important;
    overflow: hidden !important;
    width: 100%;
    padding: 12px 0 24px !important;
  }

  .certificate {
    flex: 0 0 auto;
    transform-origin: top center;
  }
}

@media print {
  .certificate {
    transform: none !important;
    transform-origin: initial !important;
  }

  .preview-area {
    height: auto !important;
    overflow: visible !important;
  }
}


/* Print one-page fix for mobile/iOS/Chrome:
   Print only the certificate at exact A4 landscape size.
*/
@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  html,
  body {
    width: 297mm !important;
    height: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
  }

  body * {
    visibility: hidden !important;
  }

  #certificate,
  #certificate * {
    visibility: visible !important;
  }

  .controls,
  .screen,
  #homeScreen,
  #loginScreen,
  #notFoundScreen {
    display: none !important;
  }

  #certificateApp,
  .preview-area {
    display: block !important;
    width: 297mm !important;
    height: 210mm !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    position: static !important;
  }

  #certificate {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: auto !important;
    width: 297mm !important;
    height: 210mm !important;
    min-height: 210mm !important;
    max-width: 297mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    transform-origin: top right !important;
    box-shadow: none !important;
    overflow: hidden !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    break-before: avoid !important;
    break-after: avoid !important;
    break-inside: avoid !important;
  }

  .template-image-layer.active {
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    width: 297mm !important;
    height: 210mm !important;
    object-fit: fill !important;
  }
}


/* PDF export button */
.buttons {
  grid-template-columns: 1fr 1fr 1fr !important;
}

.pdf-btn {
  background: #0c6b61;
  color: #fff;
}

.pdf-exporting .controls {
  pointer-events: none;
  opacity: 0.75;
}

@media (max-width: 520px) {
  .buttons {
    grid-template-columns: 1fr !important;
  }
}
