/* Received Advise — A4 sheet, preview, PDF capture (extends css/nd97-theme.css) */
:root {
  --ra-border: #1e293b;
  --ra-muted: #64748b;
  --ra-sheet-font: var(--bs-body-font-family);
  --ra-form-max: 28rem;
  --ra-pdf-page-padding-x: 12mm;
  --ra-pdf-page-padding-y: 10mm;
}

.nd97-tool-sidebar .ra-weight-summary-form {
  max-width: min(100%, var(--ra-form-max));
  margin-left: auto;
  margin-right: auto;
}

.ra-app-row {
  position: relative;
}

/* ——— Mobile / small tablets ——— */
@media (max-width: 991.98px) {
  .ra-app-root {
    padding-bottom: 1.25rem !important;
  }

  .ra-preview-col .ra-img-holder .ra-sheet-img {
    max-height: min(52vh, 520px);
  }

  .ra-head-row {
    grid-template-columns: minmax(72px, 88px) 1fr minmax(72px, 88px);
    column-gap: 0.35rem;
    min-height: 88px;
  }

  .ra-head-line {
    word-break: break-word;
  }

  .ra-logo-img {
    width: 72px;
    height: 72px;
  }

  .ra-sheet-page-footer {
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: flex-start;
  }

  .ra-sheet-timestamp {
    white-space: normal;
    word-break: break-word;
    font-size: 0.75rem;
    line-height: 1.35;
    flex: 1 1 auto;
    min-width: 0;
  }

  .ra-sheet-pagination {
    flex: 0 0 auto;
  }
}

/* Desktop: tool content fills main; form + preview scroll inside columns */
@media (min-width: 992px) {
  .ra-app-root {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    height: 100%;
  }

  .ra-app-row {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .ra-app-row > [class*='col-'] {
    min-height: 0;
  }

  .ra-form-col {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 100%;
    padding-bottom: 2rem;
    scroll-padding-bottom: 2rem;
  }

  .ra-preview-col {
    position: relative;
    top: auto;
    align-self: stretch;
    min-height: 0;
    min-width: 0;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2rem;
    scroll-padding-bottom: 2rem;
  }

  /* Trailing spacer so scroll end isn’t clipped (padding alone is unreliable for overflow:auto columns) */
  .ra-form-col::after,
  .ra-preview-col::after {
    content: '';
    display: block;
    height: 2rem;
  }
}

.letterhead {
      border-bottom: 1px solid rgba(30, 41, 59, 0.14);
      padding-bottom: 0.5rem;
      margin-bottom: 0.5rem;
      font-family: var(--ra-sheet-font);
    }

    /*
     * Letterhead: logo left, company lines optically centered on full header width
     * (matched side columns so center column is true page center).
     */
    .ra-head-row {
      display: grid;
      grid-template-columns: minmax(88px, 100px) 1fr minmax(88px, 100px);
      align-items: center;
      column-gap: 0.5rem;
      min-height: 100px;
      padding-top: 0.15rem;
    }

    .ra-head-logo-cell {
      display: flex;
      align-items: center;
      justify-content: flex-start;
    }

    .ra-head-center {
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
      min-width: 0;
    }

    .ra-head-block {
      max-width: 100%;
      text-align: center;
    }

    .ra-logo-img {
      width: 84px;
      height: 84px;
      object-fit: contain;
      flex-shrink: 0;
      border-radius: 50%;
      border: 2px solid rgba(30, 41, 59, 0.18);
      background: #fff;
      box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
    }

    /* Letterhead typography */
    .ra-head-company {
      font-size: clamp(0.98rem, 2.35vw, 1.22rem);
      font-weight: 600;
      line-height: 1.25;
      letter-spacing: 0.06em;
    }

    .ra-head-line {
      font-size: clamp(0.85rem, 1.95vw, 0.98rem);
      font-weight: 400;
      line-height: 1.45;
      margin-top: 0.28rem;
      color: #334155;
    }

    .ra-head-company + .ra-head-line {
      margin-top: 0.18rem;
    }

    .doc-title {
      font-size: clamp(1.12rem, 2.55vw, 1.48rem);
      font-weight: 700;
      letter-spacing: 0.1em;
      text-align: center;
      margin: 0.65rem 0 0.35rem;
      text-decoration: underline;
      text-underline-offset: 0.18em;
      text-decoration-thickness: 1px;
    }

    .section-label {
      font-size: 0.9rem;
      font-weight: 600;
      color: var(--ra-muted);
      text-transform: uppercase;
      letter-spacing: 0.06em;
      margin-bottom: 0.4rem;
    }

    /* Dedicated scan area: largest size that fits width, natural aspect ratio */
    .ra-img-holder {
      width: 100%;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #fafafa;
      border: 1px solid rgba(148, 163, 184, 0.35);
      border-radius: 0.5rem;
      padding: 6px;
      min-height: 200px;
    }

    .ra-img-holder .ra-sheet-img {
      max-width: 100%;
      width: auto;
      height: auto;
      max-height: min(78vh, 1100px);
      object-fit: contain;
      object-position: center;
      display: block;
      border: 0;
      background: transparent;
    }

    .embed-placeholder {
      min-height: 200px;
      width: 100%;
      border: 2px dashed rgba(79, 70, 229, 0.22);
      display: flex;
      align-items: center;
      justify-content: center;
      color: #94a3b8;
      font-size: 0.95rem;
      background: rgba(255, 255, 255, 0.7);
      border-radius: 0.45rem;
    }

    .embed-placeholder.ra-img-placeholder {
      flex-direction: column;
      gap: 0.75rem;
      padding: 1.25rem 1rem;
      box-sizing: border-box;
    }

    .ra-placeholder-inner {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 0.65rem;
      text-align: center;
    }

    .ra-placeholder-icon {
      width: 3rem;
      height: 3rem;
      flex-shrink: 0;
      color: #94a3b8;
      opacity: 0.88;
    }

    .ra-placeholder-caption {
      font-size: 0.875rem;
      color: #64748b;
      line-height: 1.35;
      max-width: 16rem;
    }

    .ra-pdf-capture .embed-placeholder.ra-img-placeholder {
      padding: 0.85rem 0.65rem;
    }

    .ra-pdf-capture .ra-placeholder-icon {
      width: 2.5rem;
      height: 2.5rem;
    }

    .ra-pdf-capture .ra-placeholder-caption {
      font-size: 0.78rem;
      max-width: 14rem;
    }

    .ra-a4-page-wrap {
      width: 100%;
      max-width: 100%;
    }

    .pdf-sheet {
      font-family: var(--ra-sheet-font);
      background: #fff;
      box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04), 0 24px 48px -20px rgba(15, 23, 42, 0.14);
      padding: var(--ra-pdf-page-padding-y) var(--ra-pdf-page-padding-x);
      width: 100%;
      max-width: 100%;
      margin: 0 auto;
      box-sizing: border-box;
      border-radius: 2px;
    }

    .ra-sheet-page-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      align-self: stretch;
      width: 100%;
      box-sizing: border-box;
      gap: 0.75rem;
      margin-top: 0.5rem;
      padding-top: 0.35rem;
      border-top: 1px solid rgba(148, 163, 184, 0.35);
      font-size: 0.8rem;
      color: var(--ra-muted);
    }

    .ra-pdf-capture .ra-sheet-page-footer {
      margin-top: auto;
    }

    .ra-sheet-timestamp {
      flex: 1 1 auto;
      min-width: 0;
      text-align: left;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .ra-sheet-pagination {
      flex: 0 0 auto;
      white-space: nowrap;
      text-align: right;
    }

    /*
     * WYSIWYG: A4 sheet (reference swamy scans) — flex column so the scan area grows
     * and pagination stays bottom-right. Same in html2canvas onclone (body.ra-pdf-capture).
     */
    .ra-pdf-capture .pdf-sheet {
      width: 210mm !important;
      max-width: 210mm !important;
      height: 297mm !important;
      min-height: 297mm !important;
      max-height: 297mm !important;
      box-sizing: border-box !important;
      padding: var(--ra-pdf-page-padding-y) var(--ra-pdf-page-padding-x) !important;
      display: flex !important;
      flex-direction: column !important;
      font-family: var(--ra-sheet-font) !important;
      overflow: hidden !important;
    }

    /* Keep header / meta blocks from shrinking; only the scan area flexes */
    .ra-pdf-capture .letterhead,
    .ra-pdf-capture .section-label,
    .ra-pdf-capture .footer-note,
    .ra-pdf-capture .ra-weight-summary,
    .ra-pdf-capture .ra-weigh-weight-line {
      flex-shrink: 0 !important;
    }

    .ra-pdf-capture .ra-head-company {
      font-size: 1.08rem !important;
      font-weight: 600 !important;
    }

    .ra-pdf-capture .ra-head-line {
      font-size: 0.9rem !important;
      font-weight: 400 !important;
    }

    .ra-pdf-capture .doc-title {
      font-size: 1.32rem !important;
      font-weight: 700 !important;
      text-decoration: underline !important;
      text-underline-offset: 0.12em !important;
    }

    .ra-pdf-capture .section-label {
      font-size: 0.9rem !important;
    }

    .ra-pdf-capture .ra-img-holder {
      flex: 1 1 auto !important;
      min-height: 0 !important;
      max-height: 100% !important;
      overflow: hidden !important;
    }

    /*
     * Fit any aspect ratio inside remaining A4 space without growing the page.
     * Use :not(.d-none) so we never override Bootstrap .d-none — otherwise empty
     * #imgInvoice stays display:block and shows the browser broken-image glyph.
     */
    .ra-pdf-capture .ra-img-holder .ra-sheet-img:not(.d-none) {
      max-width: 100% !important;
      max-height: 100% !important;
      width: auto !important;
      height: auto !important;
      object-fit: contain !important;
      object-position: center !important;
      display: block !important;
    }

    .ra-pdf-capture .ra-img-holder .embed-placeholder {
      max-width: 100% !important;
      max-height: 100% !important;
      min-height: 0 !important;
      flex: 1 1 auto !important;
      box-sizing: border-box !important;
    }

    .ra-pdf-capture .footer-note {
      font-size: 0.95rem !important;
    }

    .ra-pdf-capture .ra-sheet-page-footer {
      font-size: 0.82rem !important;
      margin-top: auto !important;
      width: 100% !important;
      justify-content: space-between !important;
      gap: 0.5rem !important;
    }

    .ra-pdf-capture .ra-sheet-timestamp {
      text-align: left !important;
    }

    .ra-pdf-capture .ra-sheet-pagination {
      text-align: right !important;
    }

    @media print {
      .ra-app-root {
        flex: none !important;
        height: auto !important;
        max-height: none !important;
        display: block !important;
        overflow: visible !important;
      }

      .ra-app-row {
        flex: none !important;
        overflow: visible !important;
      }

      .ra-form-col,
      .ra-preview-col {
        overflow: visible !important;
        max-height: none !important;
      }

      .ra-hide-preview .ra-preview-col {
        position: static !important;
        left: auto !important;
        top: auto !important;
        width: auto !important;
        max-width: none !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        z-index: auto !important;
        margin: 0 !important;
      }

      body {
        background: #fff;
      }
      .no-print {
        display: none !important;
      }
      .pdf-sheet {
        box-shadow: none;
        max-width: none;
        box-sizing: border-box;
        padding: var(--ra-pdf-page-padding-y) var(--ra-pdf-page-padding-x);
        width: 210mm;
        height: 297mm;
        min-height: 297mm;
        max-height: 297mm;
        overflow: hidden;
        display: flex;
        flex-direction: column;
      }

      .ra-img-holder {
        flex: 1 1 auto;
        min-height: 0;
        max-height: 100%;
        overflow: hidden;
      }

      .ra-img-holder .ra-sheet-img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
        object-position: center;
      }

      .ra-sheet-page-footer {
        margin-top: auto;
      }
      .ra-preview-frame {
        background: transparent;
        border: none;
        padding: 0;
        max-width: none;
      }
    }

    /* html2pdf page breaks */
    .html2pdf__page-break {
      display: block;
      page-break-before: always;
      break-before: page;
    }

    .footer-note {
      font-size: clamp(0.9rem, 2vw, 1rem);
      line-height: 1.45;
      margin-top: 0.75rem;
      padding: 0.65rem 0.9rem;
      background: linear-gradient(90deg, rgba(79, 70, 229, 0.06) 0%, rgba(241, 245, 249, 0.9) 38%, #f8fafc 100%);
      border-left: 3px solid var(--bs-primary);
      border-radius: 0 0.5rem 0.5rem 0;
    }

    .ra-weight-summary {
      font-size: clamp(0.85rem, 1.9vw, 0.98rem);
      line-height: 1.45;
      margin-top: 0.65rem;
      margin-bottom: 0.15rem;
      padding: 0.55rem 0.85rem;
      background: #f8fafc;
      border: 1px solid rgba(148, 163, 184, 0.45);
      border-radius: 0.45rem;
    }

    .ra-weight-summary-oneline {
      font-size: clamp(0.78rem, 1.75vw, 0.92rem);
      line-height: 1.35;
      white-space: nowrap;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    .ra-weight-summary-form {
      margin-top: 0;
      font-weight: 500;
      color: #334155;
    }

    .ra-weight-summary strong {
      font-weight: 700;
      color: #0f172a;
    }

    .ra-weigh-weight-line {
      font-size: clamp(0.88rem, 2vw, 0.98rem);
      margin-top: 0.5rem;
      padding: 0.45rem 0.65rem;
      background: #f1f5f9;
      border-radius: 0.35rem;
      border: 1px dashed rgba(148, 163, 184, 0.5);
    }

    .ra-weigh-weight-k {
      font-weight: 600;
      margin-right: 0.35rem;
      color: #334155;
    }

    .ra-weigh-weight-unit {
      color: var(--ra-muted);
      font-size: 0.92em;
    }

    .ra-pdf-capture .ra-weight-summary-oneline {
      font-size: 0.78rem !important;
      white-space: nowrap !important;
      overflow: visible !important;
    }

    .ra-pdf-capture .ra-weigh-weight-line {
      font-size: 0.9rem !important;
    }

    /* Preview “desk”: full width of column; sheets inside use .ra-pdf-capture = exact capture size */
    .ra-preview-frame {
      width: 100%;
      max-width: 100%;
      margin-left: auto;
      margin-right: auto;
      padding: 1rem;
      background: linear-gradient(160deg, #e2e8f0 0%, #cbd5e1 55%, #94a3b8 160%);
      border-radius: var(--bs-border-radius-lg);
      border: 1px solid rgba(255, 255, 255, 0.35);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 18px 50px -24px rgba(15, 23, 42, 0.25);
      box-sizing: border-box;
    }

    .ra-preview-frame #pdf-source.ra-a4-page-wrap {
      width: 100%;
      max-width: 100%;
      margin: 0 auto;
    }

    .ra-preview-col .pdf-sheet {
      margin-left: auto;
      margin-right: auto;
      box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06), 0 28px 56px -28px rgba(15, 23, 42, 0.22);
    }

    /*
     * Hide preview: desktop — off-screen absolute (keeps layout for html2canvas).
     * Mobile — display:none removes blank gap / extra scroll; while building PDF,
     * .ra-pdf-capture-pending on .ra-app-root restores off-screen layout for capture.
     */
    .ra-hide-preview .ra-preview-col {
      position: absolute !important;
      left: -14000px !important;
      top: 0 !important;
      width: 900px !important;
      max-width: 900px !important;
      opacity: 0 !important;
      pointer-events: none !important;
      z-index: -1 !important;
      max-height: none !important;
      overflow: visible !important;
      margin: 0 !important;
    }

    @media (max-width: 991.98px) {
      .ra-hide-preview .ra-app-row {
        --bs-gutter-y: 0;
        row-gap: 0;
      }

      .ra-hide-preview .ra-preview-col {
        display: none !important;
        position: static !important;
        left: auto !important;
        top: auto !important;
        width: 0 !important;
        max-width: 0 !important;
        height: 0 !important;
        min-height: 0 !important;
        max-height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
        opacity: 0 !important;
        border: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
      }

      .ra-hide-preview.ra-pdf-capture-pending .ra-preview-col {
        display: block !important;
        visibility: visible !important;
        position: absolute !important;
        left: -14000px !important;
        top: 0 !important;
        width: 900px !important;
        max-width: 900px !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        opacity: 0 !important;
        pointer-events: none !important;
        z-index: -1 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
      }
    }

    @media (min-width: 992px) {
      .ra-hide-preview .ra-form-col {
        flex: 0 0 100% !important;
        max-width: 100% !important;
      }
    }

    /* Weighment thumbnails list (append one image at a time) */
    .ra-weighment-list {
      max-width: 100%;
      border: 1px solid rgba(148, 163, 184, 0.35);
      border-radius: var(--bs-border-radius);
      padding: 0.25rem 0.5rem;
      background: #f8fafc;
    }

    .ra-weighment-list-row:last-child {
      border-bottom: 0 !important;
    }