/**
 * Print Stylesheet for GemCertify Certificates
 * Format: A4 Landscape (297mm x 210mm)
 * Layout: 3-column design
 */

@media print {
  /* ======================
     Page Setup
     ====================== */
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  /* Reset for print */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    color: #000 !important;
    font-family: 'Manrope', -apple-system, system-ui, sans-serif;
    font-size: 10pt;
    line-height: 1.4;
    overflow: hidden !important;
    height: 100% !important;
  }
  
  html {
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    height: 100% !important;
  }

  /* ======================
     Hide Non-Print Elements
     ====================== */
  body > *:not(.print-only) {
    display: none !important;
  }
  
  .no-print,
  header,
  nav,
  .sidebar,
  button,
  .btn,
  .filter-controls,
  .pagination,
  .print-hide,
  [onclick*="print"],
  a[href*="edit"],
  a[href*="pdf"],
  .action-buttons,
  .dark\:bg-card-dark,
  .bg-card-light,
  .container,
  #lightbox,
  script,
  style:not([media="print"]) {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  /* ======================
     Show Print-Only Elements
     ====================== */
  .print-only {
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  .print-container {
    display: flex !important;
  }

  /* ======================
     3-Column Layout
     ====================== */
  .print-certificate {
    width: 297mm !important; /* Full A4 width for scaling */
    height: 210mm !important; /* Full A4 height for scaling */
    max-width: 297mm !important;
    max-height: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 3mm;
    page-break-after: avoid !important;
    page-break-before: avoid !important;
    page-break-inside: avoid !important;
    overflow: visible !important;
    position: relative;
    transform: scale(0.92); /* Scale down to 92% to fit with margins */
    transform-origin: top left;
  }

  /* Left Column - Main Details */
  .print-column-left {
    flex: 0 0 90mm !important;
    width: 90mm !important;
    max-width: 90mm !important;
    height: 200mm !important;
    max-height: 200mm !important;
    padding: 3mm 4mm !important;
    border-right: 1px solid #ddd;
    overflow: hidden !important;
    page-break-inside: avoid !important;
  }

  /* Center Column - Large Photo */
  .print-column-center {
    flex: 0 0 125mm !important;
    width: 125mm !important;
    max-width: 125mm !important;
    height: 200mm !important;
    max-height: 200mm !important;
    padding: 3mm 4mm !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    border-right: 1px solid #ddd;
    overflow: hidden !important;
    page-break-inside: avoid !important;
  }

  /* Right Column - Compact Details */
  .print-column-right {
    flex: 0 0 65mm !important;
    width: 65mm !important;
    max-width: 65mm !important;
    height: 200mm !important;
    max-height: 200mm !important;
    padding: 3mm 4mm !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    overflow: hidden !important;
    page-break-inside: avoid !important;
  }

  /* ======================
     Typography
     ====================== */
  .print-section-title {
    font-size: 12pt;
    font-weight: 700;
    margin-bottom: 2mm;
    color: #1791cf;
    text-transform: uppercase;
    letter-spacing: 0.5pt;
  }
  
  .print-header {
    font-size: 14pt;
    font-weight: 700;
    margin-bottom: 2mm;
    color: #1791cf;
    text-transform: uppercase;
    letter-spacing: 0.5pt;
  }

  .print-field {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2mm;
    font-size: 9pt;
    line-height: 1.3;
  }

  .print-field-label {
    font-weight: 600;
    color: #333;
    flex: 0 0 auto;
  }

  .print-field-dots {
    flex: 1 1 auto;
    border-bottom: 1px dotted #999;
    margin: 0 2mm;
    height: 1em;
  }

  .print-field-value {
    font-weight: 400;
    color: #000;
    text-align: right;
    flex: 0 0 auto;
  }

  .print-field-block {
    margin-top: 3mm;
    margin-bottom: 3mm;
  }
  
  .print-field-block .print-field-label {
    font-weight: 700;
    font-size: 9pt;
    margin-bottom: 1mm;
    display: block;
  }
  
  .print-field-block .print-field-value {
    font-size: 8pt;
    line-height: 1.3;
    text-align: left;
    max-height: 20mm;
    overflow: hidden;
  }
  
  .print-description {
    margin-top: 3mm;
    padding: 2mm;
    background: #f8f9fa;
    border-left: 2px solid #1791cf;
    font-size: 8pt;
    line-height: 1.3;
    max-height: 25mm;
    overflow: hidden;
  }

  /* ======================
     Gemstones Table
     ====================== */
  .print-gemstones {
    margin-top: 4mm;
  }

  .print-gemstones-title {
    font-size: 10pt;
    font-weight: 700;
    margin-bottom: 2mm;
    color: #333;
  }

  .print-gemstones-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt;
  }

  .print-gemstones-table thead {
    background: #f0f0f0;
  }

  .print-gemstones-table th {
    padding: 2mm 1mm;
    text-align: left;
    font-weight: 600;
    font-size: 7pt;
    color: #555;
    border-bottom: 1px solid #ccc;
  }

  .print-gemstones-table td {
    padding: 1.5mm 1mm;
    border-bottom: 1px solid #eee;
    font-size: 8pt;
  }

  .print-gemstones-table tbody tr:last-child td {
    border-bottom: none;
  }

  /* ======================
     Center Column - Photo
     ====================== */
  .print-photo-main {
    width: 105mm !important;
    height: 105mm !important;
    max-width: 105mm !important;
    max-height: 105mm !important;
    object-fit: contain;
    border: 1px solid #ddd;
    margin-bottom: 3mm;
  }

  .print-photo-main img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .print-photo-placeholder {
    width: 105mm;
    height: 105mm;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 12pt;
    margin-bottom: 3mm;
  }

  .print-price-section {
    margin: 2mm 0;
  }

  .print-price {
    font-size: 16pt;
    font-weight: 700;
    color: #1791cf;
    margin: 2mm 0;
  }

  .print-qr-main {
    width: 35mm !important;
    height: 35mm !important;
    max-width: 35mm !important;
    max-height: 35mm !important;
    border: 1px solid #ddd;
    padding: 2mm;
    background: white;
    margin-top: 4mm;
  }

  .print-qr-placeholder {
    width: 35mm;
    height: 35mm;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 9pt;
    text-align: center;
  }
  
  .print-qr-label {
    font-size: 8pt;
    color: #666;
    margin-top: 1mm;
  }

  /* ======================
     Right Column - Compact
     ====================== */
  .print-compact-section {
    margin-bottom: 3mm;
  }
  
  .print-compact-title {
    font-size: 9pt;
    font-weight: 700;
    margin-bottom: 2mm;
    color: #333;
  }
  
  .print-compact-field {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.5mm;
    font-size: 7pt;
  }
  
  .print-compact-label {
    font-weight: 600;
    color: #555;
  }
  
  .print-compact-value {
    font-weight: 400;
    color: #000;
    text-align: right;
  }

  .print-column-right .print-field {
    font-size: 8pt;
  }

  .print-column-right .print-field-label {
    font-size: 7pt;
  }

  .print-column-right .print-field-value {
    font-size: 8pt;
  }

  .print-photo-small {
    width: 50mm !important;
    height: 50mm !important;
    max-width: 50mm !important;
    max-height: 50mm !important;
    object-fit: contain;
    border: 1px solid #ddd;
    margin: 3mm 0;
  }

  .print-photo-small img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .print-photo-small-placeholder {
    width: 50mm;
    height: 50mm;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 8pt;
    margin: 3mm 0;
  }

  .print-qr-small {
    width: 28mm !important;
    height: 28mm !important;
    max-width: 28mm !important;
    max-height: 28mm !important;
    border: 1px solid #ddd;
    padding: 1mm;
    background: white;
    margin-top: 4mm;
  }

  .print-qr-small-placeholder {
    width: 28mm;
    height: 28mm;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 8pt;
    text-align: center;
  }

  /* ======================
     Utilities
     ====================== */
  .print-divider {
    border-top: 1px solid #ddd;
    margin: 3mm 0;
  }

  .print-spacer {
    height: 2mm;
  }

  .print-text-center {
    text-align: center;
  }

  .print-text-bold {
    font-weight: 700;
  }

  .print-text-muted {
    color: #666;
  }

  /* ======================
     Page Breaks - Force Single Page
     ====================== */
  .print-certificate,
  .print-certificate * {
    page-break-inside: avoid !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
  }

  .print-column-left,
  .print-column-center,
  .print-column-right {
    page-break-inside: avoid !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
  }

  /* Avoid breaking tables */
  table {
    page-break-inside: avoid !important;
  }

  tr {
    page-break-inside: avoid !important;
  }
  
  /* Force content to fit */
  .print-gemstones-table {
    max-height: 50mm !important;
    overflow: hidden !important;
    font-size: 7pt !important;
  }
  
  .print-gemstones-table th {
    padding: 1mm 1mm !important;
    font-size: 6pt !important;
  }
  
  .print-gemstones-table td {
    padding: 1mm 1mm !important;
    font-size: 7pt !important;
  }
  
  .print-description {
    max-height: 25mm !important;
    overflow: hidden !important;
  }
  
  .print-field-block .print-field-value {
    max-height: 18mm !important;
  }

  /* ======================
     Images
     ====================== */
  img {
    max-width: 100%;
    height: auto;
    page-break-inside: avoid;
  }

  /* ======================
     Links (remove in print)
     ====================== */
  a[href]:after {
    content: none !important;
  }

  /* ======================
     Print-specific tweaks
     ====================== */
  
  /* Remove shadows and transitions */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
    transition: none !important;
    animation: none !important;
  }

  /* Ensure black text */
  p, span, div, td, th {
    color: #000 !important;
  }

  /* Headings */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    color: #000 !important;
  }
}
