/* ============================================================
   AnyCheck Calibration Certificate — Exact A4 Layout & Print Styles
   ============================================================ */

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: #dde1e7;
  color: #000000;
  font-family: "SimHei", "STHeiti", "Heiti SC", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ==================== Top Toolbar ==================== */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #cbd5e1;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  padding: 10px 16px;
}

.toolbar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.toolbar-brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toolbar-title {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
}

.toolbar-subtitle {
  font-family: Arial, sans-serif;
  font-size: 11px;
  color: #64748b;
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar-controls button {
  appearance: none;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.toolbar-controls button:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.toolbar-controls button.btn-primary {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #ffffff;
}

.toolbar-controls button.btn-primary:hover {
  background: #1e40af;
  border-color: #1e40af;
}

.toolbar-controls button.btn-danger {
  color: #b91c1c;
  border-color: #fecaca;
}

.toolbar-controls button.btn-danger:hover {
  background: #fef2f2;
  border-color: #f87171;
}

#save-status {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 12px;
  color: #475569;
  padding: 4px 8px;
  background: #f1f5f9;
  border-radius: 4px;
  white-space: nowrap;
}

/* ==================== Pages Desk Container ==================== */

.pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18pt;
  padding: 20pt 12pt 36pt;
}

.a4-page {
  width: 595.25pt;
  height: 841.85pt;
  position: relative;
  background: #ffffff;
  overflow: hidden;
  box-sizing: border-box;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.16);
  flex-shrink: 0;
}

.page-bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

.page-header-logo {
  left: 36.60pt;
  top: 25.80pt;
  width: 475.24pt;
  height: 70.81pt;
  display: block;
  pointer-events: none;
  user-select: none;
}

/* All foreground content sits cleanly above page_bg (watermark + stamp) */
.abs {
  position: absolute;
  z-index: 2;
  line-height: 1;
  white-space: nowrap;
}

/* ==================== Font Families ==================== */

.font-simhei {
  font-family: "SimHei", "STHeiti", "Heiti SC", "PingFang SC", sans-serif;
}

.font-simsun {
  font-family: "SimSun", "STSong", "Songti SC", "Noto Serif CJK SC", serif;
}

.font-yahei {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

.font-times {
  font-family: "Times New Roman", Times, "STSong", "Songti SC", serif;
}

.font-arial {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}

/* ==================== Interactive Inputs ==================== */

.cert-input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 0 2pt;
  border: 0.75pt dashed rgba(37, 99, 235, 0.45);
  border-radius: 2pt;
  background: rgba(239, 246, 255, 0.45);
  color: #000000;
  line-height: 1.15;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.cert-input:hover {
  border-color: rgba(37, 99, 235, 0.75);
  background: rgba(239, 246, 255, 0.7);
}

.cert-input:focus {
  border-style: solid;
  border-color: #2563eb;
  background: rgba(239, 246, 255, 0.85);
  box-shadow: 0 0 0 1.5pt rgba(37, 99, 235, 0.18);
}

/* Pure Preview Mode & Print Mode: completely clean, borderless, transparent */
body.preview-mode .cert-input {
  border-color: transparent !important;
  background: transparent !important;
  box-shadow: none !important;
}

body.preview-mode .edit-only-ui {
  display: none !important;
}

/* ==================== Page 1 Specifics ==================== */

.cnas-logo {
  left: 415.08pt;
  top: 129.84pt;
  width: 160.56pt;
  height: 51.36pt;
  display: block;
}

.p1-title-cn {
  left: 215.88pt;
  top: 138.85pt;
  width: 186.13pt;
  font-size: 33.84pt;
  display: flex;
  justify-content: space-between;
}

.p1-title-en {
  left: 206.39pt;
  top: 180.26pt;
  font-size: 14.99pt;
  font-weight: 700;
}

#barcode-box {
  left: 54.60pt;
  top: 194.52pt;
  width: 110.88pt;
  height: 30.12pt;
  overflow: hidden;
}

#barcode-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.p1-cert-input {
  left: 108.50pt;
  top: 232.30pt;
  width: 106pt;
  height: 13pt;
  font-size: 9.35pt;
}

.field-char {
  font-size: 10.29pt;
}

.field-sub-en {
  font-size: 10.29pt;
}

.main-field-input {
  left: 174.24pt;
  width: 391.20pt;
  height: 14.50pt;
  font-size: 10.29pt;
}

.h-rule {
  height: 0.84pt;
  background: #000000;
}

.h-rule-thick {
  height: 0.96pt;
  background: #000000;
}

/* QR Code Upload Zone & Hint */
.qr-hint-stack {
  left: 16pt;
  top: 533.76pt;
  width: 86pt;
  display: flex;
  flex-direction: column;
  gap: 4pt;
  white-space: normal;
}

.qr-hint-badge {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 6.5pt;
  line-height: 1.35;
  color: #1e40af;
  background: #eff6ff;
  border: 0.6pt solid #bfdbfe;
  border-radius: 3pt;
  padding: 3.5pt 4.5pt;
}

.qr-warning {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 6.3pt;
  line-height: 1.3;
  color: #9a3412;
  background: #fff7ed;
  border: 0.6pt solid #fdba74;
  border-radius: 3pt;
  padding: 3pt 4.5pt;
}

#qr-upload-zone {
  left: 108.36pt;
  top: 533.76pt;
  width: 69.00pt;
  height: 75.60pt;
  border: 0.9pt dashed rgba(37, 99, 235, 0.6);
  background: rgba(239, 246, 255, 0.35);
  border-radius: 2pt;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

#qr-upload-zone.has-qr {
  border-color: rgba(148, 163, 184, 0.45);
  background: transparent;
}

#qr-upload-zone.drag-over {
  border-style: solid;
  border-color: #2563eb;
  background: rgba(219, 234, 254, 0.65);
}

body.preview-mode #qr-upload-zone {
  border: none !important;
  background: transparent !important;
  cursor: default;
}

#qr-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3pt;
  width: 100%;
  height: 100%;
  padding: 4pt;
  text-align: center;
  white-space: normal;
}

#btn-upload-qr {
  appearance: none;
  border: 0.6pt solid #2563eb;
  background: #2563eb;
  color: #ffffff;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 7pt;
  padding: 2.5pt 5pt;
  border-radius: 2.5pt;
  cursor: pointer;
  line-height: 1.2;
}

#btn-upload-qr:hover {
  background: #1d4ed8;
}

.qr-placeholder-hint {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 6.2pt;
  color: #475569;
  line-height: 1.2;
}

.qr-change-btn {
  position: absolute;
  bottom: 2pt;
  left: 50%;
  transform: translateX(-50%);
  appearance: none;
  border: none;
  background: rgba(15, 23, 42, 0.76);
  color: #ffffff;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 6.2pt;
  padding: 1.5pt 5pt;
  border-radius: 2pt;
  cursor: pointer;
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

#qr-upload-zone:hover .qr-change-btn,
.qr-change-btn:focus-visible {
  opacity: 1;
}

/* Dates Page 1 */
.date-input {
  height: 13pt;
  font-size: 9.35pt;
  text-align: center;
  padding: 0 1pt;
}

.date-unit {
  font-size: 9.35pt;
}

.date-sub-en {
  font-size: 9.35pt;
}

/* Signatures Page 1 */
.sig-img {
  width: 68.28pt;
  height: 28.32pt;
  display: block;
  object-fit: contain;
}

/* Footer Page 1 */
.footer-text {
  font-size: 8.51pt;
}

/* ==================== Page 2 Specifics ==================== */

.p2-title-cn {
  left: 223.21pt;
  top: 106.58pt;
  width: 154.30pt;
  font-size: 27.95pt;
  display: flex;
  justify-content: space-between;
}

.p2-title-en {
  left: 211.66pt;
  top: 139.47pt;
  font-size: 14.00pt;
}

.p2-text {
  font-size: 9.95pt;
}

.p2-cert-input {
  left: 113.20pt;
  top: 162.80pt;
  width: 110pt;
  height: 13.50pt;
  font-size: 9.95pt;
}

.p2-date-input {
  height: 13.50pt;
  font-size: 9.95pt;
  text-align: center;
  padding: 0 1pt;
}

/* Standards Table */
.std-table {
  left: 50.40pt;
  top: 368.16pt;
  width: 499.20pt;
  table-layout: fixed;
  border-collapse: collapse;
  border: 0.96pt solid #000000;
  white-space: normal;
}

.std-table th,
.std-table td {
  border: 0.96pt solid #000000;
  padding: 0;
  margin: 0;
  text-align: center;
  font-size: 9.95pt;
  font-weight: normal;
  color: #000000;
  box-sizing: border-box;
}

.std-head-row th {
  height: 70.32pt;
  vertical-align: top;
  padding-top: 3.5pt;
  line-height: 12.2pt;
}

.th-cn,
.th-en {
  line-height: 12.2pt;
}

.nowrap-sm {
  display: inline-block;
  white-space: nowrap;
  font-size: 9.2pt;
}

.std-data-row td {
  height: 17.88pt;
  vertical-align: middle;
  line-height: 1;
}

.std-cell-input {
  padding: 0 2pt !important;
}

.table-input {
  width: 100%;
  height: 14pt;
  font-size: 9.95pt;
  text-align: center;
  padding: 0 1pt;
  display: block;
}

.u-sub {
  font-size: 6.45pt;
  vertical-align: -2pt;
  margin-left: 1.2pt;
}

/* ==================== Page 3 Specifics ==================== */

.p3-title-cn {
  left: 238.50pt;
  top: 127.66pt;
  width: 117.00pt;
  font-size: 24.00pt;
  display: flex;
  justify-content: space-between;
}

.p3-title-en {
  left: 249.00pt;
  top: 161.27pt;
  font-size: 9.95pt;
}

.p3-text {
  font-size: 9.95pt;
}

.p3-cert-input {
  left: 106.00pt;
  top: 174.90pt;
  width: 110pt;
  height: 13.50pt;
  font-size: 9.95pt;
}

.p3-divider {
  left: 55.68pt;
  top: 200.04pt;
  width: 518.40pt;
  height: 2.88pt;
  display: block;
}

/* ==================== Responsive Screen Scaling ==================== */

@media screen and (max-width: 826px) {
  .pages-container {
    zoom: calc((100vw - 16px) / 794px);
    padding: 12pt 0 24pt;
  }
}

/* ==================== Print Styles (Exact 3 A4 Pages) ==================== */

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    width: 595.25pt;
    height: auto !important;
  }

  .no-print,
  .edit-only-ui {
    display: none !important;
  }

  .pages-container {
    zoom: 1 !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
  }

  .a4-page {
    width: 595.25pt !important;
    height: 840pt !important;
    box-shadow: none !important;
    margin: 0 !important;
    page-break-inside: avoid;
    break-inside: avoid;
    page-break-after: always;
    break-after: page;
  }

  .a4-page .page-bg {
    width: 595.25pt;
    height: 841.85pt;
  }

  .a4-page:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  .cert-input {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
  }

  #qr-upload-zone {
    border: none !important;
    background: transparent !important;
  }
}
