/* ==========================================================================
   ALGEX SDX — Sovereign Certificate Stylesheet (Strictly Light Mode & Print)
   ========================================================================== */

.cert-page-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 0 4rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: clip;
}

/* ==========================================================================
   1. Control Bar (Screen Only)
   ========================================================================== */
.cert-controls-bar {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-glass-hover);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
}

[data-theme="light"] .cert-controls-bar {
  background: #FFFFFF;
  border-color: #CBD5E1;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.cert-ctrl-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.cert-status-badge {
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #10B981;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

[data-theme="light"] .cert-status-badge {
  background: #ECFDF5;
  color: #047857;
  border-color: #A7F3D0;
}

.cert-mode-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.cert-ctrl-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.btn-cert-download {
  background: linear-gradient(135deg, #10B981, #047857) !important;
  color: #FFFFFF !important;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none !important;
  transition: var(--transition-fast);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.btn-cert-download:hover,
.btn-cert-download:focus,
.btn-cert-download:active {
  background: linear-gradient(135deg, #059669, #047857) !important;
  color: #FFFFFF !important;
  text-decoration: none !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5) !important;
}

.btn-cert-download span,
.btn-cert-download i {
  color: #FFFFFF !important;
}

.btn-cert-print {
  background: linear-gradient(135deg, #2563EB, #1D4ED8);
  color: #FFFFFF;
  border: none;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition-fast);
}

.btn-cert-print:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
}

.btn-cert-back {
  background: transparent;
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-cert-back:hover {
  border-color: var(--quantum-blue);
  color: var(--quantum-blue-light);
}

/* ==========================================================================
   2. Horizontal Scroll Wrapper & Sovereign Document Container
   ========================================================================== */
.cert-doc-scroll-wrap {
  width: 100%;
  max-width: 900px;
  min-width: 0;
  margin: 0 auto;
  position: relative;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cert-mobile-scroll-hint {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(37, 99, 235, 0.12);
  border: 1px dashed rgba(59, 130, 246, 0.4);
  color: var(--quantum-blue-light);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
  text-align: center;
}

[data-theme="light"] .cert-mobile-scroll-hint {
  background: #EFF6FF;
  border-color: #BFDBFE;
  color: #1D4ED8;
}

.sovereign-document {
  width: 100%;
  max-width: 900px;
  background: #FFFFFF !important;
  color: #0F172A !important;
  border: 2px solid #CBD5E1;
  border-radius: 12px;
  padding: 2.5rem 2.5rem;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25);
  font-family: var(--font-primary), 'Segoe UI', Tahoma, sans-serif;
  position: relative;
  box-sizing: border-box;
}

/* Document Header */
.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1.25rem;
}

.doc-logo-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.doc-header-text {
  flex: 1;
  text-align: center;
}

.doc-republic-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: #0F172A;
  margin-bottom: 0.2rem;
}

.doc-platform-title {
  font-size: 1.25rem;
  font-weight: 900;
  color: #1E40AF;
  margin-bottom: 0.25rem;
}

.doc-protocol-sub {
  font-size: 0.76rem;
  font-weight: 700;
  color: #475569;
}

.doc-decree-tag {
  font-size: 0.72rem;
  font-weight: 800;
  color: #B45309;
  margin-top: 0.2rem;
}

.doc-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.qr-mockup {
  width: 56px;
  height: 56px;
  border: 1.5px solid #0F172A;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #0F172A;
  background: #F8FAFC;
}

.qr-label {
  font-size: 0.62rem;
  font-weight: 800;
  color: #047857;
}

.doc-divider {
  height: 2px;
  background: linear-gradient(90deg, #1E40AF, #CBD5E1, #047857);
  margin-bottom: 1.5rem;
}

/* Document Title Section */
.doc-title-section {
  text-align: center;
  margin-bottom: 1.5rem;
}

.doc-main-title {
  font-size: 1.35rem;
  font-weight: 900;
  color: #0F172A;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}

.doc-en-sub {
  font-size: 0.72rem;
  font-weight: 800;
  color: #64748B;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Metadata Bar */
.doc-meta-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  background: #F0FDF4;
  border: 1.5px solid #BBF7D0;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 1.75rem;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: center;
}

.meta-item .lbl {
  font-size: 0.68rem;
  font-weight: 700;
  color: #475569;
}

.meta-item .val {
  font-size: 0.82rem;
  font-weight: 900;
  color: #0F172A;
}

.text-blue { color: #1E40AF !important; }
.text-green { color: #047857 !important; }
.text-gold { color: #B45309 !important; }

/* Document Sections */
.doc-section {
  margin-bottom: 1.5rem;
}

.doc-section-title {
  font-size: 0.95rem;
  font-weight: 900;
  color: #1E40AF;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sec-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #1E40AF;
  color: #FFFFFF;
  font-size: 0.7rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.doc-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1.5px solid #CBD5E1;
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.82rem;
  background: #FFFFFF;
  margin-bottom: 0.5rem;
  box-sizing: border-box;
}

.doc-table th, .doc-table td {
  border: none;
  border-bottom: 1px solid #CBD5E1;
  border-left: 1px solid #CBD5E1;
  padding: 0.55rem 0.8rem;
  text-align: right;
}

.doc-table tr:last-child td {
  border-bottom: none;
}

.doc-table th:last-child,
.doc-table td:last-child {
  border-left: none;
}

.doc-table th {
  background: #F1F5F9;
  color: #1E293B;
  font-weight: 800;
}

.font-bold { font-weight: 800; }
.font-mono { font-family: var(--font-mono), monospace; }

/* Formula Box */
.doc-formula-box {
  background: #F8FAFC;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.formula-render {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-family: var(--font-mono), monospace;
  color: #0F172A;
  margin-bottom: 0.55rem;
  direction: ltr;
  white-space: nowrap;
  flex-wrap: nowrap;
}

.f-part {
  background: #E2E8F0;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.f-var {
  font-weight: 700;
  font-family: var(--font-mono), monospace;
}

.f-ar {
  font-family: var(--font-family);
  font-size: 0.72rem;
  font-weight: 600;
  direction: rtl;
}

.f-op {
  font-weight: 800;
  color: #475569;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.formula-calc-structured {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #FFFFFF;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  margin: 0.55rem 0;
  flex-wrap: nowrap;
  gap: 0.35rem;
  width: 100%;
  box-sizing: border-box;
}

.calc-lead-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: #0F172A;
  white-space: nowrap;
  flex-shrink: 0;
}

.calc-math-equation {
  font-family: var(--font-mono), monospace;
  font-size: 0.74rem;
  color: #1E293B;
  direction: ltr;
  white-space: nowrap;
  flex-shrink: 0;
}

.calc-arrow-symbol {
  font-size: 0.95rem;
  font-weight: 900;
  color: #2563EB;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 0 0.15rem;
}

.gex-pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #FEF3C7;
  border: 1.5px solid #F59E0B;
  padding: 0.18rem 0.5rem;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.12);
  white-space: nowrap;
  flex-shrink: 0;
}

.gex-pill-val {
  font-family: var(--font-mono), monospace;
  font-size: 0.82rem;
  font-weight: 900;
  color: #B45309;
}

.gex-pill-lbl {
  font-size: 0.72rem;
  font-weight: 800;
  color: #92400E;
}

.formula-note {
  font-size: 0.68rem;
  color: #64748B;
  line-height: 1.4;
  margin: 0;
}

/* Crypto Grid */
.doc-crypto-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.crypto-card {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
}

.c-title {
  font-size: 0.72rem;
  font-weight: 800;
  color: #1E293B;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.c-code {
  font-family: var(--font-mono), monospace;
  font-size: 0.68rem;
  color: #475569;
  word-break: break-all;
  direction: ltr;
  display: block;
}

/* Signatures & Seal Section */
.doc-signatures-section {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1.3fr;
  gap: 1rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1.5px dashed #CBD5E1;
}

.sig-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.official-seal-badge {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px dashed #B45309;
  background: #FFFBEB;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 4px 15px rgba(180, 83, 9, 0.15);
}

.seal-icon {
  font-size: 1.35rem;
  color: #B45309;
}

.seal-txt-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.s-top { font-size: 0.55rem; font-weight: 700; color: #92400E; }
.s-main { font-size: 0.65rem; font-weight: 900; color: #B45309; }
.s-bot { font-size: 0.52rem; font-weight: 700; color: #92400E; }

.sig-role {
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748B;
  margin-bottom: 0.2rem;
}

.sig-name {
  font-size: 0.95rem;
  font-weight: 900;
  color: #0F172A;
  margin-bottom: 0.15rem;
}

.sig-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.35rem;
}

.sig-attest {
  font-size: 0.62rem;
  font-weight: 800;
  color: #047857;
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.doc-footer {
  text-align: center;
  font-size: 0.65rem;
  color: #94A3B8;
  margin-top: 1.75rem;
  padding-top: 0.85rem;
  border-top: 1px solid #E2E8F0;
}

/* ==========================================================================
   3. Responsive Rules & Mobile Horizontal Scrolling (Screen Only)
   ========================================================================== */
@media screen and (max-width: 920px) {
  .cert-mobile-scroll-hint {
    display: flex;
  }

  .cert-doc-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.75rem;
  }

  .sovereign-document {
    min-width: 760px;
    width: 760px;
    margin: 0 auto;
    padding: 2rem 1.75rem;
  }
}


@media screen and (max-width: 768px) {
  .cert-page-wrap {
    padding: 0.75rem 0.5rem 3.5rem;
    width: 100%;
    align-items: stretch;
  }

  .cert-controls-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.85rem;
    width: 100%;
  }

  .cert-ctrl-info {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.35rem;
    width: 100%;
  }

  .cert-status-badge {
    width: 100%;
    font-size: 0.76rem;
    white-space: normal;
    text-align: center;
    justify-content: center;
    padding: 0.35rem 0.5rem;
    border-radius: 999px;
    box-sizing: border-box;
  }

  .cert-mode-tag {
    font-size: 0.72rem;
    justify-content: center;
    text-align: center;
  }

  .cert-ctrl-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    width: 100%;
  }

  .btn-cert-download {
    grid-column: span 1;
    justify-content: center;
    padding: 0.55rem 0.25rem;
    font-size: 0.72rem;
    text-align: center;
    white-space: normal;
    line-height: 1.2;
  }

  .btn-cert-print {
    grid-column: span 1;
    justify-content: center;
    padding: 0.55rem 0.25rem;
    font-size: 0.72rem;
    text-align: center;
    white-space: normal;
    line-height: 1.2;
  }

  .btn-cert-back {
    grid-column: span 2;
    justify-content: center;
    padding: 0.55rem 0.75rem;
    font-size: 0.8rem;
  }

  .cert-doc-scroll-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 1rem;
    box-sizing: border-box;
  }

  .sovereign-document {
    min-width: 740px !important;
    width: 740px !important;
    padding: 1.75rem 1.5rem !important;
    margin: 0 !important;
  }
}


/* ==========================================================================
   4. Print Rules (@media print)
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm 12mm;
  }

  html,
  body {
    background: #FFFFFF !important;
    background-color: #FFFFFF !important;
    color: #0F172A !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Completely eliminate non-printable elements, widgets, drawer, backdrop and nav */
  .site-header,
  .site-footer,
  .no-print,
  .cert-controls-bar,
  .cert-mobile-scroll-hint,
  .btn-back-to-top,
  .ai-widget-wrapper,
  .ai-floating-widget,
  .ai-launcher-btn,
  .ai-modal-container,
  #ai-widget-wrapper,
  #ai-assistant-modal,
  .mobile-bottom-dock,
  .mobile-drawer,
  .drawer-backdrop,
  #mobile-drawer,
  #drawer-backdrop,
  .mobile-nav-toggle,
  .theme-toggle-btn {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
  }

  .main-content,
  .app-container,
  .cert-page-wrap,
  .cert-doc-scroll-wrap {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    box-shadow: none !important;
    border: none !important;
    overflow: visible !important;
    background: transparent !important;
  }

  .sovereign-document {
    border: none !important;
    box-shadow: none !important;
    padding: 0 4px !important;
    max-width: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    margin: 0 auto !important;
    background: #FFFFFF !important;
    box-sizing: border-box !important;
  }

  /* Section Pagination & Preventing Orphan Titles */
  .doc-section {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .doc-section-title,
  h1, h2, h3, h4, h5, h6 {
    break-after: avoid !important;
    page-break-after: avoid !important;
  }

  /* Force Section 3 to start cleanly on Page 2 with its cards & signatures */
  .doc-section-crypto {
    break-before: page !important;
    page-break-before: always !important;
    margin-top: 0 !important;
    padding-top: 0.5rem !important;
  }

  .doc-header,
  .doc-title-section,
  .doc-table,
  .doc-formula-box,
  .doc-crypto-grid,
  .crypto-card,
  .doc-signatures-section,
  .sig-block,
  .doc-footer {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .doc-table {
    border-collapse: separate !important;
    border-spacing: 0 !important;
    border: 1.5px solid #CBD5E1 !important;
    border-radius: 6px !important;
    overflow: hidden !important;
    width: 100% !important;
  }

  .doc-table th, .doc-table td {
    border: none !important;
    border-bottom: 1px solid #CBD5E1 !important;
    border-left: 1px solid #CBD5E1 !important;
  }

  .doc-table tr:last-child td {
    border-bottom: none !important;
  }

  .doc-table th:last-child,
  .doc-table td:last-child {
    border-left: none !important;
  }

  /* Strip all shadows from document elements during print to prevent edge artifacts */
  *, *::before, *::after {
    box-shadow: none !important;
    text-shadow: none !important;
  }
}
