/* Shared document layout: legal text and brand stay in the document flow. */
.preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-bottom: 36px !important;
  overflow: visible;
}

.preview > * {
  flex-shrink: 0;
}

.preview .document-title-block,
.preview .party-card,
.preview .property-card,
.preview .party-text {
  min-width: 0;
}

.preview .party-name,
.preview .party-text,
.preview .subtitle,
.preview .periode,
.preview .signature,
.preview .commentaire-zone,
.preview .mention-legale,
.preview .table-quittance th,
.preview .table-quittance td,
.preview .table-recu th,
.preview .table-recu td {
  overflow-wrap: anywhere;
}

.preview .commentaire-zone {
  white-space: pre-wrap;
  line-height: 1.6 !important;
}

.preview .document-signature-box {
  max-width: 100%;
}

.preview .document-footer {
  position: static;
  width: 100%;
  margin-top: auto;
  padding-top: 28px;
  break-inside: avoid;
}

.preview .document-footer .mention-legale-secondaire {
  position: static !important;
  inset: auto !important;
  width: 100%;
  margin: 0 !important;
  padding-top: 12px !important;
  border-top: 1px solid #d9dee7 !important;
  color: #525b68 !important;
  font-size: 11px !important;
  line-height: 1.5 !important;
  text-align: left !important;
}

.preview .document-credit {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  color: #525b68;
  font-size: 10.5px;
  line-height: 1.5;
  text-align: center;
}

.preview .document-credit img {
  display: block;
  flex: 0 0 auto;
  width: 16px;
  height: 18px;
  object-fit: contain;
}

/* The app version sits below the paper, outside the PDF capture. */
.document-quota-shell > .version-app {
  position: static;
  margin: 10px 0 0;
  padding: 0 4px;
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
  overflow-wrap: anywhere;
}

/* The PDF renderer uses this class so phone styles never alter the A4 capture. */
.preview.document-pdf-capture {
  flex: none !important;
  width: 794px !important;
  height: auto !important;
  min-height: 1123px !important;
  margin: 0 !important;
  padding: 52.9px !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  transform: none !important;
}

.preview.document-pdf-capture .version-app {
  display: none !important;
}

.preview.document-pdf-capture .document-top {
  display: flex !important;
  flex-direction: row !important;
  gap: 28px !important;
}

.preview.document-pdf-capture .document-top .signature {
  flex: 0 0 210px !important;
  min-width: 210px !important;
  text-align: right !important;
}

.preview.document-pdf-capture .document-parties {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  gap: 26px !important;
}

@media screen and (max-width: 900px) {
  .preview:not(.document-pdf-capture) {
    flex: 0 0 auto;
    width: 100%;
    min-height: 0;
    padding: 28px 20px !important;
  }

  .preview:not(.document-pdf-capture) .document-top {
    flex-direction: column !important;
    gap: 16px !important;
  }

  .preview:not(.document-pdf-capture) .document-top .signature {
    flex: 0 0 auto !important;
    min-width: 0 !important;
    width: 100%;
    text-align: left !important;
  }

  .preview:not(.document-pdf-capture) .document-parties {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 24px !important;
    margin-top: 28px;
  }

  .preview:not(.document-pdf-capture) .party-name {
    font-size: 16px;
    line-height: 1.4;
  }

  .preview:not(.document-pdf-capture) .party-text {
    font-size: 14px !important;
    line-height: 1.55 !important;
  }

  .preview:not(.document-pdf-capture) .document-footer {
    margin-top: 0;
    padding-top: 28px;
  }

  .preview:not(.document-pdf-capture) .document-footer .mention-legale-secondaire {
    font-size: 13px !important;
    line-height: 1.6 !important;
  }

  .preview:not(.document-pdf-capture) .document-credit {
    font-size: 12px;
    margin-top: 18px;
  }

  .preview:not(.document-pdf-capture) .version-app {
    position: static;
    margin-top: 14px;
    text-align: right;
  }
}

@media screen and (max-width: 480px) {
  /* Native date controls have a minimum content width. Stack editor fields
     before two date inputs can exceed the available phone panel width. */
  .form-section .row-2 {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .form-section .row-2 .input-group {
    flex: 0 1 auto;
    width: 100%;
    min-width: 0;
  }

  .form-section .row-2 input {
    min-width: 0;
    max-width: 100%;
  }

  .preview:not(.document-pdf-capture) {
    padding: 24px 16px !important;
  }

  .preview:not(.document-pdf-capture) h1 {
    font-size: 24px !important;
    line-height: 1.15 !important;
  }

  .preview:not(.document-pdf-capture) .table-quittance,
  .preview:not(.document-pdf-capture) .table-recu {
    font-size: 13px;
  }

  .preview:not(.document-pdf-capture) .table-quittance th,
  .preview:not(.document-pdf-capture) .table-quittance td,
  .preview:not(.document-pdf-capture) .table-recu th,
  .preview:not(.document-pdf-capture) .table-recu td {
    padding: 10px 6px !important;
  }

  .preview:not(.document-pdf-capture) .table-quittance th:first-child,
  .preview:not(.document-pdf-capture) .table-quittance td:first-child,
  .preview:not(.document-pdf-capture) .table-recu th:first-child,
  .preview:not(.document-pdf-capture) .table-recu td:first-child {
    width: 64% !important;
  }

  .preview:not(.document-pdf-capture) .table-quittance th:nth-child(2),
  .preview:not(.document-pdf-capture) .table-quittance td:nth-child(2),
  .preview:not(.document-pdf-capture) .table-recu th:nth-child(2),
  .preview:not(.document-pdf-capture) .table-recu td:nth-child(2) {
    width: 36% !important;
  }
}

@media print {
  .version-app {
    display: none !important;
  }

  .preview {
    display: flex !important;
    height: auto !important;
    min-height: 297mm !important;
    padding: 14mm !important;
    overflow: visible !important;
  }
}
