/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

img {
  max-width: 100%;
  display: block;
}

/* === CSS Custom Properties === */
:root {
  --primary-color:    #1a2e4a;
  --secondary-color:  #c8a951;
  --background-color: #ffffff;
  --text-color:       #333333;
  --muted-color:      #777777;
  --border-color:     #c8a951;
  --border-width:     7px;
  --font-heading:     'Playfair Display', Georgia, serif;
  --font-body:        'Lato', 'Helvetica Neue', sans-serif;
}

/* === Body Base === */
body {
  font-family: var(--font-body);
  color: var(--text-color);
  background-color: var(--background-color);
}

/* === SPA View System === */
.view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
}

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

/* === Loading Spinner === */
.loading-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(200, 169, 81, 0.2);
  border-top-color: var(--secondary-color, #c8a951);
  border-right-color: var(--primary-color, #1a2e4a);
  animation: spin 0.9s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}

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

/* === Error / Not-Found View === */

#error-view {
  background: linear-gradient(135deg, #0d1b2a 0%, #1a2e4a 45%, #0f2236 100%);
}

.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 44px 40px 40px;
  text-align: center;
  background: #ffffff;
  border-top: 3px solid var(--secondary-color, #c8a951);
  border-radius: 16px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(200, 169, 81, 0.12);
  max-width: 420px;
  width: 90%;
}

.error-illustration {
  margin-bottom: 4px;
}

.error-message {
  font-size: 1.15rem;
  font-family: var(--font-heading, Georgia, serif);
  color: var(--primary-color, #1a2e4a);
  margin: 0;
  font-weight: 700;
  line-height: 1.3;
}

.error-tagline {
  font-size: 0.85rem;
  font-family: var(--font-body, system-ui, sans-serif);
  color: var(--muted-color, #777);
  margin: 0;
  font-style: italic;
  opacity: 0.8;
}

.error-detail {
  font-size: 0.82rem;
  font-family: var(--font-body, system-ui, sans-serif);
  color: var(--muted-color, #666666);
  margin: 0;
  line-height: 1.55;
  background: rgba(26, 46, 74, 0.05);
  border-radius: 6px;
  padding: 8px 14px;
  word-break: break-all;
}

.error-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ffffff;
  background: var(--primary-color, #1a2e4a);
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  min-height: 44px;
  cursor: pointer;
  margin-top: 6px;
  transition: background 200ms ease, transform 150ms ease, box-shadow 200ms ease;
  box-shadow: 0 4px 16px rgba(26, 46, 74, 0.25);
}

.error-retry-btn:hover {
  background: #223a5e;
  box-shadow: 0 6px 20px rgba(26, 46, 74, 0.35);
}

.error-retry-btn:active {
  transform: scale(0.97);
}

.error-retry-btn:focus-visible {
  outline: 2px solid var(--secondary-color, #c8a951);
  outline-offset: 2px;
}

/* ========================================
   SEARCH / LANDING PAGE
   ======================================== */

#search-view {
  background: linear-gradient(135deg, #0d1b2a 0%, #1a2e4a 45%, #0f2236 100%);
  padding: 40px 16px;
  position: relative;
  overflow: hidden;
}

#search-view::before,
#search-view::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

#search-view::before {
  width: 480px;
  height: 480px;
  top: -140px;
  right: -100px;
  background: radial-gradient(circle, rgba(200, 169, 81, 0.13) 0%, transparent 68%);
}

#search-view::after {
  width: 360px;
  height: 360px;
  bottom: -120px;
  left: -80px;
  background: radial-gradient(circle, rgba(200, 169, 81, 0.07) 0%, transparent 68%);
}

.search-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.97);
  border-top: 3px solid var(--secondary-color);
  border-radius: 16px;
  padding: 44px 40px 40px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(200, 169, 81, 0.12);
  text-align: center;
  position: relative;
  z-index: 1;
}

.search-logo {
  max-height: 60px;
  max-width: 180px;
  object-fit: contain;
}

.search-org-name {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--primary-color);
  text-transform: uppercase;
  opacity: 0.6;
  margin: -4px 0 0;
  text-align: center;
}

.search-headline {
  font-family: var(--font-heading);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--primary-color);
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.search-subtext {
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--muted-color);
  margin: 0;
  line-height: 1.6;
  max-width: 320px;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.search-label {
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--primary-color);
  text-align: left;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  opacity: 0.75;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-icon {
  position: absolute;
  left: 14px;
  color: var(--muted-color);
  pointer-events: none;
  flex-shrink: 0;
  opacity: 0.55;
}

.search-input {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-color);
  background: #f8f7f4;
  border: 1.5px solid rgba(26, 46, 74, 0.15);
  border-radius: 8px;
  padding: 13px 14px 13px 42px;
  width: 100%;
  outline: none;
  transition: border-color 200ms ease, box-shadow 200ms ease, background 200ms ease;
}

.search-input:focus {
  background: #ffffff;
  border-color: var(--secondary-color);
  box-shadow: 0 0 0 3px rgba(200, 169, 81, 0.2);
}

.search-input::placeholder {
  color: var(--muted-color);
  opacity: 0.55;
}

.search-btn {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--primary-color);
  background: var(--secondary-color);
  border: none;
  border-radius: 8px;
  padding: 14px 20px;
  width: 100%;
  cursor: pointer;
  min-height: 48px;
  transition: background 200ms ease, transform 150ms ease, box-shadow 200ms ease;
  box-shadow: 0 4px 16px rgba(200, 169, 81, 0.35);
}

.search-btn:hover {
  background: #d9bb62;
  box-shadow: 0 6px 20px rgba(200, 169, 81, 0.45);
}

.search-btn:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(200, 169, 81, 0.25);
}

.search-btn:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.search-footer-note {
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--muted-color);
  margin: 0;
  opacity: 0.75;
  line-height: 1.5;
}

/* ========================================
   FLOATING DOWNLOAD BUTTON
   ======================================== */

.btn-download {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 10px 20px;
  min-height: 44px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: var(--secondary-color);
  color: var(--primary-color);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  transition: background 200ms ease, transform 150ms ease, box-shadow 200ms ease;
}

.btn-download:hover {
  background: #d9bb62;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.btn-download:focus-visible {
  outline: 2px solid var(--secondary-color);
  outline-offset: 3px;
}

.btn-download:active {
  transform: scale(0.97);
}

.pdf-download-help {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 100;
  width: min(320px, calc(100vw - 40px));
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(13, 27, 42, 0.96);
  color: #ffffff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.pdf-download-help-text {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.5;
}

.pdf-open-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--secondary-color);
  color: var(--primary-color);
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.pdf-open-link:hover {
  background: #d9bb62;
}

.pdf-open-link:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* ========================================
   CERTIFICATE PAGE BACKDROP
   ======================================== */

/* Premium dark backdrop makes the certificate card pop */
#certificate-view {
  background: linear-gradient(160deg, var(--primary-color) 0%, #0b1824 100%);
  padding: 24px 0;
  align-items: center;
}

/* ========================================
   CERTIFICATE CARD
   ======================================== */

/* Wrapper: floating-card depth via filter drop-shadow */
/* container-type enables cqw units inside — all cert sizes scale with card width */
.certificate-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0 16px;
  max-width: 1050px;
  margin: 0 auto;
  width: 100%;
  filter: drop-shadow(0 24px 64px rgba(0, 0, 0, 0.55));
  container-type: inline-size;
}

body.pdf-exporting #certificate-view {
  background: white;
  padding: 0;
}

body.pdf-exporting .certificate-wrapper {
  width: var(--pdf-export-width, 297mm);
  max-width: none;
  padding: 0;
  margin: 0 auto;
  filter: none;
}

/* A4 landscape proportions on screen (297mm x 210mm) */
.certificate {
  width: 100%;
  aspect-ratio: 297 / 210;
  background: radial-gradient(ellipse at 50% 40%, #ffffff 0%, #f8f5ee 100%);
  border: var(--border-width) double var(--border-color);
  font-family: var(--font-body);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  padding: 2.8cqw 4.4cqw 2.6cqw;
  box-sizing: border-box;
  position: relative;
  /* Inner gold border drawn via outline with negative offset */
  outline: 1.5px solid rgba(200, 169, 81, 0.45);
  outline-offset: -1.8cqw;
  /* Force all colors and backgrounds to print exactly as shown on screen
     This fixes logos and text being invisible when 'Background graphics' is OFF */
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body.pdf-exporting .certificate {
  width: var(--pdf-export-width, 297mm);
  height: var(--pdf-export-height, 210mm);
  aspect-ratio: auto;
  padding: 12mm 18mm 10mm;
  outline: none;
  overflow: hidden;
}

.pdf-export-host {
  position: fixed;
  top: 0;
  left: -200vw;
  z-index: -1;
  width: var(--pdf-export-width, 297mm);
  height: var(--pdf-export-height, 210mm);
  overflow: hidden;
  pointer-events: none;
}

.pdf-export-host .certificate-wrapper {
  width: var(--pdf-export-width, 297mm);
  max-width: none;
  padding: 0;
  margin: 0;
  filter: none;
}

.pdf-export-host .certificate {
  width: 100%;
}

.pdf-export-host .cert-heading-label {
  line-height: 1;
  position: relative;
  top: -0.12cqw;
}

.pdf-export-host .cert-name::after {
  margin-top: 1.75cqw;
}

/* Corner L-bracket ornaments via CSS multi-background gradients */
.certificate::before {
  content: '';
  position: absolute;
  top: 2.8cqw;
  left: 2.8cqw;
  right: 2.8cqw;
  bottom: 2.8cqw;
  background:
    /* Top-left corner */
    linear-gradient(var(--secondary-color), var(--secondary-color)) top left / 2.2cqw 1.5px no-repeat,
    linear-gradient(var(--secondary-color), var(--secondary-color)) top left / 1.5px 2.2cqw no-repeat,
    /* Top-right corner */
    linear-gradient(var(--secondary-color), var(--secondary-color)) top right / 2.2cqw 1.5px no-repeat,
    linear-gradient(var(--secondary-color), var(--secondary-color)) top right / 1.5px 2.2cqw no-repeat,
    /* Bottom-left corner */
    linear-gradient(var(--secondary-color), var(--secondary-color)) bottom left / 2.2cqw 1.5px no-repeat,
    linear-gradient(var(--secondary-color), var(--secondary-color)) bottom left / 1.5px 2.2cqw no-repeat,
    /* Bottom-right corner */
    linear-gradient(var(--secondary-color), var(--secondary-color)) bottom right / 2.2cqw 1.5px no-repeat,
    linear-gradient(var(--secondary-color), var(--secondary-color)) bottom right / 1.5px 2.2cqw no-repeat;
  pointer-events: none;
}

/* Header: org logo above org name, centered */
.cert-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8cqw;
  margin-bottom: 1.2cqw;
}

.cert-logo {
  max-height: 7.2cqw;
  max-width: 22cqw;
  object-fit: contain;
}

.cert-org-name {
  font-family: var(--font-body);
  font-size: 1.25cqw;
  letter-spacing: 0.06em;
  color: var(--secondary-color);
  margin: 0;
  text-align: center;
}

.cert-event-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.3cqw;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--primary-color);
  margin: 0.2cqw 0 0;
  text-align: center;
}

/* Title block: gradient ornament line — heading label — gradient ornament line */
.cert-title-block {
  display: flex;
  align-items: center;
  gap: 1.4cqw;
  margin-bottom: 1.6cqw;
}

/* Gradient-fade ornament lines (more elegant than flat gold) */
.cert-ornament-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent 0%,
    var(--secondary-color) 30%,
    var(--secondary-color) 70%,
    transparent 100%
  );
}

.cert-heading-label {
  font-family: var(--font-heading);
  font-size: 2.2cqw;
  font-style: italic;
  color: var(--primary-color);
  white-space: nowrap;
  margin: 0;
  letter-spacing: 0.04em;
}

/* Body: pre-name text, recipient name, post-name, workshop, description */
.cert-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.4cqw;
}

.cert-pre-name-text,
.cert-post-name-text {
  font-family: var(--font-body);
  font-size: 1.5cqw;
  color: var(--muted-color);
  margin: 0;
  letter-spacing: 0.02em;
}

.cert-name {
  font-family: var(--font-heading);
  font-size: 5.4cqw;
  font-weight: 700;
  color: var(--secondary-color);
  margin: 0.5cqw 0 0.3cqw;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

/* Gold accent bar beneath the recipient name */
.cert-name::after {
  content: '';
  display: block;
  width: 8cqw;
  height: 2px;
  background: var(--secondary-color);
  margin: 1cqw auto 0;
  border-radius: 2px;
}

.cert-workshop {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 2.2cqw;
  font-weight: 500;
  font-style: normal;
  color: var(--primary-color);
  margin: 0.5cqw 0 0;
  opacity: 0.88;
}

.cert-description {
  font-family: var(--font-body);
  font-size: 1.4cqw;
  color: var(--muted-color);
  max-width: 80%;
  text-align: center;
  font-style: italic;
  margin: 0.5cqw 0 0;
  line-height: 1.55;
}

/* Footer: gold separator + date left, seal center, signature right */
.cert-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 1cqw;
  padding-top: 1cqw;
  border-top: 1px solid rgba(200, 169, 81, 0.35);
}

.cert-footer-left,
.cert-footer-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3cqw;
  min-width: 13cqw;
}

.cert-footer-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4cqw;
}

.cert-date {
  font-family: var(--font-body);
  font-size: 1.4cqw;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.cert-seal {
  max-height: 7.2cqw;
  max-width: 7.2cqw;
  object-fit: contain;
  opacity: 0.92;
}

.cert-signature {
  max-height: 5.2cqw;
  max-width: 15cqw;
  object-fit: contain;
}

.cert-authorized-name {
  font-family: var(--font-body);
  font-size: 1.4cqw;
  font-weight: 700;
  color: var(--text-color);
  margin: 0;
  padding-top: 0.5cqw;
  border-top: 1.5px solid rgba(26, 46, 74, 0.3);
  width: 100%;
  text-align: center;
}

.cert-footer-label {
  font-family: var(--font-body);
  font-size: 1.15cqw;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--secondary-color);
}

.cert-seal-label {
  font-family: var(--font-heading);
  font-size: 1.25cqw;
  font-style: italic;
  letter-spacing: 0.06em;
  color: var(--secondary-color);
  margin: 0;
}

/* QR code: centered inline block after description text */
.cert-qr-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5cqw;
  margin-top: 1cqw;
}

.cert-qr {
  line-height: 0; /* collapse gap under canvas/img */
}

.cert-qr canvas,
.cert-qr img {
  width: 6.8cqw !important;
  height: 6.8cqw !important;
  display: block;
}

.cert-qr-label {
  font-family: var(--font-body);
  font-size: 1cqw;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted-color);
  opacity: 0.8;
}

/* ========================================
   PRINT / PDF (A4 Landscape)
   ======================================== */

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

  body {
    margin: 0;
    background: white;
  }

  /* Reset page backdrop for print */
  #certificate-view {
    background: white !important;
    padding: 0;
  }

  /* Hide all views except certificate during print */
  .view {
    display: none !important;
  }

  /* Hide action bar and any no-print elements */
  .no-print {
    display: none !important;
  }

  #certificate-view {
    display: flex !important;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 0;
  }

  .certificate-wrapper {
    padding: 0;
    max-width: none;
    filter: none;
  }

  /* Override screen aspect-ratio with exact physical dimensions */
  .certificate {
    width: 297mm;
    height: 210mm;
    aspect-ratio: auto;
    padding: 12mm 18mm 10mm;
    box-shadow: none;
    outline: none;
    /* Ensure print-color-adjust works in both Chromium and Firefox */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* QR canvas renders exactly as on screen — needed for clean PDF output */
  .cert-qr canvas,
  .cert-qr img {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Print-safe inner border via positioned ::after */
  .certificate::after {
    content: '';
    position: absolute;
    top: 8mm;
    left: 8mm;
    right: 8mm;
    bottom: 8mm;
    border: 0.4pt solid rgba(200, 169, 81, 0.5);
    pointer-events: none;
  }

  .cert-heading-label {
    line-height: 1;
    position: relative;
    top: -0.12cqw;
  }

  .cert-name::after {
    margin-top: 1.35cqw;
  }
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  /* Move download button to a full-width bottom bar on mobile */
  .btn-download {
    top: auto;
    bottom: 16px;
    left: 16px;
    right: 16px;
    width: calc(100% - 32px);
    justify-content: center;
    border-radius: 10px;
  }

  .pdf-download-help {
    top: auto;
    right: 16px;
    bottom: 72px;
    left: 16px;
    width: auto;
  }

  /* Add bottom padding so button doesn't overlap certificate */
  #certificate-view {
    padding-top: 12px;
    padding-bottom: 80px;
    justify-content: flex-start;
  }

  /* Tighter horizontal padding on search card for narrow screens */
  .search-container {
    padding: 32px 20px 28px;
  }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
    border: 3px solid var(--secondary-color, #c8a951);
  }
}
