/* ============================================================
   CHA DOC SYSTEM VERIFICATION - Static (HTML/CSS/JS) build
   Converted from the React project. Same design, layout, text,
   responsive behavior and print workflow. Demo/sample only.
   ============================================================ */

:root {
  --cha-black: #000000;
  --cha-footer: #111111;
  --cha-red: #dc2626;
  --cha-red-hover: #b91c1c;
  --cha-red-active: #991b1b;
  --cha-page-bg: #f0f0f0;
  --cha-field-label-bg: #f5f5f5;
  --cha-border: #d1d5db;
}

* { box-sizing: border-box; border-width: 0; border-style: solid; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #111827;
  background: #ffffff;
}

a { color: inherit; text-decoration: inherit; }
img, svg { display: block; vertical-align: middle; }
button { font-family: inherit; cursor: pointer; background: transparent; padding: 0; color: inherit; }
h1 { margin: 0; font-size: inherit; font-weight: inherit; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }

.App { min-height: 100vh; display: flex; flex-direction: column; text-align: left; }

.max-wrap { max-width: 1280px; margin-left: auto; margin-right: auto; }

/* ---------------- Icons ---------------- */
.icon { width: 24px; height: 24px; stroke: currentColor; stroke-width: 2; fill: none;
  stroke-linecap: round; stroke-linejoin: round; }
.spin { animation: cha-spin 1s linear infinite; }
@keyframes cha-spin { to { transform: rotate(360deg); } }

/* ---------------- Header ---------------- */
.cha-header { background: var(--cha-black); width: 100%; }
.cha-header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 20px;
}
.cha-brand { display: flex; align-items: center; cursor: pointer; user-select: none; }
.cha-mark { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.cha-mark-row { display: flex; align-items: center; }
.cha-mark-row .tile { margin-right: 3px; }
.cha-mark-name { font-weight: 900; color: #ffffff; line-height: 1; font-size: 14px; }
.cha-mark-sub { color: #9ca3af; font-weight: 700; letter-spacing: 0.22em; margin-top: 2px; font-size: 7.5px; }
.cha-divider { width: 1px; height: 28px; background: var(--cha-red); margin: 0 12px; }
.cha-brand-text { display: flex; flex-direction: column; line-height: 1; }
.cha-brand-text .org { color: #ffffff; font-weight: 700; font-size: 13px; }
.cha-brand-text .sys { color: #9ca3af; font-size: 10.5px; margin-top: 2px; }

.cha-header-actions { display: none; align-items: center; gap: 8px; }
.btn-login {
  background: var(--cha-red); color: #fff; font-size: 13px; font-weight: 600;
  padding: 6px 20px; transition: background-color .15s ease;
}
.btn-login:hover { background: var(--cha-red-hover); }
.btn-register {
  border: 1px solid var(--cha-red); color: #fff; font-size: 13px; font-weight: 600;
  padding: 6px 20px; transition: background-color .15s ease;
}
.btn-register:hover { background: rgba(127, 29, 29, 0.3); }
.lang-toggle {
  display: flex; border: 1px solid #4b5563; font-size: 12px; font-weight: 700;
  margin-left: 4px; overflow: hidden;
}
.lang-toggle button { padding: 6px 10px; color: #d1d5db; transition: background-color .15s ease; }
.lang-toggle button:hover { background: #374151; }
.lang-toggle button.active { background: var(--cha-red); color: #fff; }

.cha-hamburger { color: #fff; padding: 4px; display: inline-flex; }
.cha-hamburger .icon { width: 22px; height: 22px; }

.cha-mobile-menu {
  display: none; background: #000; border-top: 1px solid #1f2937;
  padding: 0 20px 16px; flex-direction: column; gap: 8px;
}
.cha-mobile-menu.open { display: flex; }
.cha-mobile-menu .btn-login,
.cha-mobile-menu .btn-register { width: 100%; padding: 8px 0; text-align: center; }
.cha-mobile-menu .btn-login { margin-top: 12px; }
.cha-mobile-menu .lang-toggle { width: max-content; margin-left: 0; }
.cha-mobile-menu .lang-toggle button { padding: 6px 12px; }

/* ---------------- Demo banner ---------------- */
.cha-demo-banner {
  background: #fef3c7; color: #92400e; border-bottom: 1px solid #fcd34d;
  text-align: center; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  padding: 6px 12px; line-height: 1.4;
}

/* ---------------- Content / red bar ---------------- */
.cha-content { flex: 1 1 0%; background: var(--cha-page-bg); }
.cha-redbar { background: var(--cha-red); padding: 18px 20px; }
.cha-redbar h1 { color: #fff; font-size: 22px; font-weight: 700; }
.cha-redbar-inner { display: flex; align-items: center; justify-content: space-between; }
.cha-redbar-actions { display: flex; gap: 8px; }
.btn-bar {
  display: inline-flex; align-items: center; gap: 8px; font-weight: 600;
  font-size: 14px; padding: 8px 16px; transition: background-color .15s ease;
}
.btn-bar .icon { width: 14px; height: 14px; }
.btn-back-bar { background: #fff; color: var(--cha-red-hover); }
.btn-back-bar:hover { background: #f3f4f6; }
.btn-print-bar { background: #000; color: #fff; }
.btn-print-bar:hover { background: #1f2937; }

/* ---------------- Verify card ---------------- */
.cha-verify-container { padding: 48px 20px; display: flex; justify-content: center; }
.cha-verification-card {
  background: #fff; box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
  width: 100%; max-width: 680px; padding: 32px;
}
.cha-form { max-width: 384px; margin: 0 auto; }
.cha-form > * + * { margin-top: 20px; }
.cha-form label {
  display: block; font-size: 13px; color: #374151; margin-bottom: 6px; font-weight: 500;
}
.cha-form input {
  width: 100%; border: 1px solid var(--cha-border); padding: 10px 16px;
  font-size: 13px; outline: none; transition: border-color .15s ease;
}
.cha-form input::placeholder { color: #9ca3af; }
.cha-form input:focus { border-color: #6b7280; }
.cha-error { color: var(--cha-red); font-size: 13px; }
.btn-verify {
  width: 100%; background: var(--cha-red); color: #fff; font-weight: 700;
  padding: 12px 0; font-size: 13px; transition: background-color .15s ease;
}
.btn-verify:hover { background: var(--cha-red-hover); }
.btn-verify:active { background: var(--cha-red-active); }
.cha-hint { font-size: 11px; color: #9ca3af; text-align: center; padding-top: 4px; }

/* ---------------- Loading ---------------- */
.cha-loading {
  flex: 1 1 0%; background: var(--cha-page-bg);
  display: flex; align-items: center; justify-content: center; min-height: 40vh;
}
.cha-loading .box { text-align: center; }
.cha-spinner { position: relative; width: 56px; height: 56px; margin: 0 auto 16px; }
.cha-spinner .ring { position: absolute; inset: 0; border: 4px solid #fee2e2; border-radius: 9999px; }
.cha-spinner .arc { position: absolute; inset: 0; border: 4px solid transparent; border-top-color: var(--cha-red); border-radius: 9999px; }
.cha-spinner .center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.cha-spinner .center .icon { width: 18px; height: 18px; color: var(--cha-red); }
.cha-loading .label { color: #374151; font-weight: 600; font-size: 14px; }

/* ---------------- Result ---------------- */
.cha-result-outer { flex: 1 1 0%; background: var(--cha-page-bg); }
.cha-result-container { padding: 32px 20px; }
.cha-result-card {
  background: #fff; box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
  max-width: 680px; margin: 0 auto; padding: 24px;
}
.cha-success {
  display: flex; align-items: center; gap: 12px; margin-bottom: 24px;
  padding-bottom: 20px; border-bottom: 1px solid #e5e7eb;
}
.cha-success .icon { width: 20px; height: 20px; color: #16a34a; flex-shrink: 0; }
.cha-success p { font-weight: 700; color: #111827; font-size: 15px; }

.cha-applicant-photo { margin-bottom: 20px; }
.cha-applicant-photo img {
  width: 160px; height: 200px; object-fit: cover; object-position: top;
  border: 1px solid var(--cha-border);
}

.cha-fields { margin-bottom: 28px; }
.cha-fields > * + * { margin-top: 6px; }
.cha-field { border: 1px solid var(--cha-border); overflow: hidden; }
.cha-field .label {
  background: var(--cha-field-label-bg); border-bottom: 1px solid var(--cha-border);
  padding: 3px 10px;
}
.cha-field .label span {
  font-size: 10px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.025em;
}
.cha-field .value { background: #fff; padding: 6px 10px; }
.cha-field .value span { font-size: 12px; font-weight: 600; color: #111827; }

.cha-doc-section { margin-bottom: 8px; }
.cha-doc-section .heading {
  font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase;
  letter-spacing: 0.025em; margin-bottom: 8px;
}
.cha-document-preview { width: 100%; height: 600px; border: 2px solid #1a1a1a; background: #fff; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.cha-document-preview img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center; }
@media (max-width: 767px) { .cha-document-preview { height: 55vh; min-height: 320px; } }
.cha-document-preview .cha-doc-placeholder {
  display: flex; align-items: center; justify-content: center; min-height: 220px;
  color: #6b7280; font-size: 13px; text-align: center; padding: 24px;
}

.cha-note { margin-top: 24px; display: flex; align-items: flex-start; gap: 16px; }
.cha-note .qr { flex-shrink: 0; border: 1px solid var(--cha-border); padding: 4px; background: #fff; }
.cha-note .qr .icon { width: 72px; height: 72px; color: #1f2937; stroke-width: 1.2; }
.cha-note .text { font-size: 11px; line-height: 1.625; color: #374151; font-family: "Times New Roman", serif; }
.cha-note .text p + p { margin-top: 4px; }
.cha-note .text .strong { font-weight: 600; }
.cha-note .text a { color: #2563eb; text-decoration: underline; }

.cha-disclaimer {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid #e5e7eb;
  font-size: 11px; line-height: 1.625; color: #4b5563; font-family: "Times New Roman", serif;
}
.cha-disclaimer .italic { font-style: italic; margin-top: 4px; }

.cha-result-actions { margin-top: 24px; display: flex; gap: 12px; }
.btn-back {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--cha-border);
  color: #374151; font-size: 14px; font-weight: 600; padding: 10px 20px; transition: background-color .15s ease;
}
.btn-back:hover { background: #f3f4f6; }
.btn-back .icon { width: 14px; height: 14px; }
.btn-print {
  display: inline-flex; align-items: center; gap: 8px; background: var(--cha-red);
  color: #fff; font-size: 14px; font-weight: 600; padding: 10px 20px; transition: background-color .15s ease;
}
.btn-print:hover { background: var(--cha-red-hover); }
.btn-print .icon { width: 14px; height: 14px; }

/* ---------------- Footer ---------------- */
.cha-footer { background: var(--cha-footer); color: #fff; margin-top: auto; }
.cha-footer-grid {
  padding: 40px 20px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 32px;
}
.cha-footer-brand { grid-column: span 2 / span 2; }
.cha-footer-brand .cha-brand { margin-bottom: 12px; }
.cha-footer-brand p { color: #6b7280; font-size: 12px; line-height: 1.625; }
.cha-footer-col h4 {
  font-weight: 700; font-size: 14px; margin: 0 0 12px; text-transform: uppercase;
  letter-spacing: 0.025em; color: #e5e7eb;
}
.cha-footer-col ul li + li { margin-top: 8px; }
.cha-footer-col ul a { color: #9ca3af; font-size: 14px; transition: color .15s ease; }
.cha-footer-col ul a:hover { color: #fff; }
.cha-footer-bottom { border-top: 1px solid #1f2937; }
.cha-footer-bottom-inner {
  padding: 16px 20px; display: flex; flex-direction: column; align-items: center;
  justify-content: space-between; gap: 8px;
}
.cha-footer-bottom-inner p { color: #4b5563; font-size: 12px; }
.cha-footer-bottom-inner .ssl { display: flex; align-items: center; gap: 6px; color: #4b5563; font-size: 12px; }
.cha-footer-bottom-inner .ssl .icon { width: 11px; height: 11px; }

/* Compact brand (footer) */
.cha-brand.compact .cha-mark-name { font-size: 13px; }
.cha-brand.compact .cha-mark-sub { font-size: 7px; color: #6b7280; }
.cha-brand.compact .cha-divider { height: 24px; margin: 0 10px; }
.cha-brand.compact .cha-brand-text .org { font-size: 11px; }
.cha-brand.compact .cha-brand-text .sys { font-size: 9px; color: #6b7280; }

/* ---------------- Responsive ---------------- */
@media (min-width: 768px) {
  .cha-header-actions { display: flex; }
  .cha-hamburger { display: none; }
  .cha-mobile-menu { display: none !important; }
  .cha-verification-card { padding: 48px; }
  .cha-result-card { padding: 32px; }
  .cha-footer-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .cha-footer-brand { grid-column: span 1 / span 1; }
  .cha-footer-bottom-inner { flex-direction: row; }
}

/* ---------------- DB-driven additions (position/size preserved) ---------------- */
/* QR is now a record-specific image loaded from the database, shown in the
   SAME 72px box as the original design. */
.cha-note .qr img { width: 70px !important; height: 70px !important; display: block; object-fit: contain !important; object-position: center; }

/* Optional record-specific CHA organization stamp. Absolutely positioned so it
   never shifts any existing element in the approved layout. Only rendered when
   the verified record has an organization_image value. */
.cha-result-card { position: relative; }
.cha-org-stamp {
  position: absolute; top: 24px; right: 24px; width: 56px; height: 56px;
  object-fit: contain; object-position: center; opacity: 0.95;
}
@media (min-width: 768px) { .cha-org-stamp { top: 32px; right: 32px; width: 64px; height: 64px; } }

/* Optional site-wide logo image variant of the brand tile (same footprint). */
.cha-mark .tile-img { width: 18px; height: 16px; object-fit: contain; margin-right: 3px; border-radius: 1.5px; }
.cha-brand.compact .tile-img { width: 16px; height: 14px; }

/* Transient loading overlay shown during verification (preserves the original
   loading-spinner UX). Not part of any page's static layout. */
.cha-loading-overlay {
  position: fixed; inset: 0; background: var(--cha-page-bg);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.cha-loading-overlay.show { display: flex; }
.cha-loading-overlay .box { text-align: center; }
.cha-loading-overlay .label { color: #374151; font-weight: 600; font-size: 14px; }

/* ---------------- Print (exact 3-page workflow) ---------------- */
.cha-print-only { display: none; }

/* Normal result: logo stays with the QR/verification block, never at the top. */
.cha-note .org-logo-box {
  flex-shrink: 0; border: 1px solid var(--cha-border); padding: 4px; background: #fff;
  display: flex; align-items: center; justify-content: center;
}
.cha-note .org-logo-box img { width: 70px !important; height: 70px !important; object-fit: contain !important; object-position: center; display: block; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff !important; }

  /* Page 1 is ONLY the existing verification result/details.
     The on-screen document preview and note are moved to dedicated pages. */
  .cha-result-card {
    box-shadow: none !important; max-width: 100% !important; margin: 0 !important;
    page-break-after: always;
  }
  .cha-result-card .cha-doc-section,
  .cha-result-card .cha-note,
  .cha-result-card .cha-disclaimer,
  .cha-result-card .cha-result-actions {
    display: none !important;
  }

  .cha-print-only { display: block; }
  .cha-print-page {
    width: 100%; min-height: 100vh; page-break-before: always;
    page-break-after: always; display: flex; align-items: flex-start;
    justify-content: center; padding: 0; box-sizing: border-box;
  }
  .cha-print-page:last-child { page-break-after: auto; }

  /* Page 2: one record-specific document image. */
  .cha-print-document-page img {
    display: block; width: 100%; height: auto; max-height: 100vh;
    object-fit: contain; margin: 0 auto;
  }
  .cha-print-document-page .cha-doc-placeholder {
    width: 100%; min-height: 240px; display: flex; align-items: center;
    justify-content: center; color: #6b7280; font-size: 13px;
  }

  /* Page 3: QR + organization logo + the editable DB note. */
  .cha-print-verification-page { align-items: flex-start; padding: 28px 20px; }
  .cha-print-verification-inner { width: 100%; max-width: 900px; }
  .cha-print-verification-assets {
    display: flex; align-items: center; gap: 18px; margin-bottom: 18px;
  }
  .cha-print-verification-assets img {
    width: 82px; height: 82px; object-fit: contain; object-position: center; display: block;
  }
  .cha-print-note-text {
    font-size: 11px; line-height: 1.625; color: #374151;
    font-family: "Times New Roman", serif;
  }
  .cha-print-note-text p + p { margin-top: 5px; }
  .cha-print-note-text .strong { font-weight: 600; }
  .cha-print-note-text .italic { font-style: italic; }
}

/* Final QR + CHA logo size override */
.cha-note .qr img { width:70px !important; height:70px !important; }
.cha-note .org-logo-box { width:70px !important; height:70px !important; padding:4px; box-sizing:border-box; }
.cha-note .org-logo-box img { width:70px !important; height:70px !important; }


/* ============================================================================
   FINAL HANDOVER OVERRIDES — sizes are controlled from config.php ($UI).
   ============================================================================ */
.cha-applicant-photo img { width: var(--cha-photo-width) !important; height: var(--cha-photo-height) !important; object-fit: cover; }
.cha-photo-placeholder { width: var(--cha-photo-width); height: var(--cha-photo-height); border: 1px solid #d1d5db; background:#f5f5f5; }
.cha-document-preview { height: var(--cha-document-height); }
.cha-document-preview img { width:100%; height:100%; object-fit:contain; }
.cha-document-preview iframe { width:100%; height:100%; border:0; display:block; background:#fff; }
.cha-note .qr { width: calc(var(--cha-qr-size) + 10px); height: calc(var(--cha-qr-size) + 10px); flex:0 0 auto; display:flex; align-items:center; justify-content:center; }
.cha-note .qr img { width:var(--cha-qr-size) !important; height:var(--cha-qr-size) !important; max-width:none !important; max-height:none !important; object-fit:contain !important; }
.cha-note .org-logo-box { width:calc(var(--cha-org-logo-size) + 10px) !important; height:calc(var(--cha-org-logo-size) + 10px) !important; flex:0 0 auto; padding:4px; box-sizing:border-box; display:flex; align-items:center; justify-content:center; }
.cha-note .org-logo-box img { width:var(--cha-org-logo-size) !important; height:var(--cha-org-logo-size) !important; max-width:none !important; max-height:none !important; object-fit:contain !important; }
.cha-print-document-page iframe { width:100%; height:100vh; border:0; display:block; }
@media print {
  .cha-print-document-page img { max-height:100vh; }
}

/* CHA_HEADER_FOOTER_SVG_PATH_FIX_V1 */
.cha-mark .cha-full-brand-logo {
  display: block;
  width: auto;
  height: 42px;
  max-width: 220px;
  object-fit: contain;
}
.cha-brand.compact .cha-mark .cha-full-brand-logo {
  height: 34px;
  max-width: 180px;
}
