/* === Salvaguardias responsive globales =====================
   Driver Docs inyecta dinámicamente HTML (escrito jurídico,
   anexos, paywall, vista previa). Estas reglas garantizan que
   el contenido nunca desborde el viewport en móvil aunque traiga
   palabras largas, tablas, imágenes base64 o URLs sin espacios. */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}
body.escritos-page,
body.driver-docs-page,
body.driver-lex-page,
body.tools-page {
  overflow-x: hidden;
}

/* Cinturón de seguridad responsive: ningún descendiente directo de tool-card,
   tool-info, fieldset o preview puede forzar más ancho que su contenedor.
   Aplica con prioridad razonable a Driver-Lex (que es donde el bug aparecía
   tras cargar PDF: <pre> con texto extraído, status messages, etc.). */
.driver-lex-page .tool-card,
.driver-lex-page .tool-info,
.driver-lex-page fieldset,
.driver-lex-page .form-notice {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.driver-lex-page .tool-card *,
.driver-lex-page .tool-info * {
  max-width: 100%;
  min-width: 0;
}
.driver-lex-page pre,
.driver-lex-page code,
.driver-lex-page textarea {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
  box-sizing: border-box;
}

/* Cualquier imagen, canvas, video, iframe inyectado dinámicamente NO debe
   superar el ancho del viewport bajo ningún concepto. Aplica a TODO el
   árbol de escritos/docs/lex. Especialmente crítico en móvil cuando se cargan
   fotos base64 o canvas con width=2200. */
.escritos-page img,
.escritos-page canvas,
.escritos-page video,
.escritos-page iframe,
.driver-docs-page img,
.driver-docs-page canvas,
.driver-docs-page video,
.driver-docs-page iframe,
.driver-lex-page img,
.driver-lex-page canvas,
.driver-lex-page video,
.driver-lex-page iframe,
.tools-page img,
.tools-page canvas,
.tools-page video,
.tools-page iframe {
  max-width: 100%;
  height: auto;
}
/* El canvas de firma tiene height fijo deliberado; lo eximimos. */
.escritos-page #signatureCanvas {
  height: 220px;
}

.escritos-page .tool-card,
.escritos-page .tool-info,
.escritos-page .signature-block {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  box-sizing: border-box;
  padding: 18px;
  margin-bottom: 20px;
  max-width: 100%;
  min-width: 0;
}

/* Cualquier contenido dentro de tool-card no puede desbordar */
.escritos-page .tool-card > *,
.escritos-page .preview-card > * {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

.escritos-page .escritos-form {
  display: grid;
  gap: 18px;
}

.driver-lex-query textarea,
#driverLexQuery {
  min-height: 280px;
  resize: vertical;
}

.escritos-page fieldset {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  padding: 16px;
  margin: 0;
}

.escritos-page legend {
  padding: 0 8px;
  font-weight: 700;
}

.escritos-page label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.escritos-page input,
.escritos-page select,
.escritos-page textarea {
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: #111;
  font: inherit;
}

.escritos-page textarea {
  min-height: 96px;
  resize: vertical;
}

.escritos-page select option {
  color: #111;
}

.escritos-page input::placeholder,
.escritos-page textarea::placeholder {
  color: #555;
}

.escritos-page input:focus-visible,
.escritos-page select:focus-visible,
.escritos-page textarea:focus-visible,
.escritos-page canvas:focus-visible {
  outline: 3px solid rgba(255,255,255,.42);
  outline-offset: 3px;
}

.escritos-page .tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.escritos-page .tool-button,
.escritos-page input[type="file"]::file-selector-button,
.escritos-page input[type="file"]::-webkit-file-upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 132px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid rgba(15, 42, 15, 0.22);
  border-radius: 10px;
  color: #123012;
  background: linear-gradient(180deg, #f1f4f1 0%, #dfe5df 100%);
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 42, 15, 0.08), 0 8px 18px rgba(15, 42, 15, 0.08);
}

.escritos-page .tool-button:hover,
.escritos-page .tool-button:active,
.escritos-page .tool-button:focus-visible,
.escritos-page input[type="file"]::file-selector-button:hover,
.escritos-page input[type="file"]::file-selector-button:active,
.escritos-page input[type="file"]:focus-visible::file-selector-button,
.escritos-page input[type="file"]::-webkit-file-upload-button:hover,
.escritos-page input[type="file"]::-webkit-file-upload-button:active {
  border-color: rgba(15, 42, 15, 0.32);
  background: linear-gradient(180deg, #ffffff 0%, #f6f8f6 100%);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(15, 42, 15, 0.12), 0 12px 22px rgba(15, 42, 15, 0.10);
}

.escritos-page .tool-button:focus-visible,
.escritos-page input[type="file"]:focus-visible::file-selector-button {
  outline: 3px solid rgba(15, 42, 15, 0.28);
  outline-offset: 3px;
}

.escritos-page .escritos-form input[type="date"] {
  max-width: 11rem;
  width: 100%;
}

.escritos-page .writing-radio-group,
.escritos-page .writing-attachments {
  display: grid;
  gap: 10px;
}

.escritos-page .writing-attachments {
  grid-column: 1 / -1;
  align-items: start;
}

.escritos-page .writing-radio-group label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.escritos-page .writing-radio-group input {
  width: auto;
  min-height: auto;
}

.escritos-page .attachment-list {
  display: grid;
  gap: 8px;
  padding-left: 0;
  list-style: none;
}

.escritos-page .attachment-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.escritos-page .attachment-list li > span {
  flex: 1 1 200px;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.escritos-page .attachment-list button {
  width: auto;
  flex: 0 0 auto;
}

/* Lista de adjuntos en Driver Lex — mismo layout que escritos-page. */
.driver-lex-page .attachment-list {
  display: grid;
  gap: 8px;
  padding-left: 0;
  list-style: none;
  max-width: 100%;
  box-sizing: border-box;
}
.driver-lex-page .attachment-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.driver-lex-page .attachment-list li > span {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.driver-lex-page .attachment-list button {
  flex: 0 0 auto;
  width: auto;
}

.escritos-page #addAttachmentFiles {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  align-self: start;
  width: auto;
  max-width: max-content;
  gap: .4rem;
  white-space: normal;
}

.escritos-page .writing-attachments input[type="file"] {
  color: inherit;
}

.escritos-page .audit-actions,
.escritos-page .audit-template-list {
  display: grid;
  gap: 12px;
}

.escritos-page .audit-actions {
  margin: 14px 0;
}

.escritos-page .audit-template-item {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  box-sizing: border-box;
  padding: 12px;
}

.escritos-page .audit-template-item h3 {
  margin: 0 0 10px;
}

.escritos-page .audit-template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.escritos-page .signature-block {
  display: grid;
  gap: 12px;
}

.escritos-page .signature-block canvas {
  width: 100%;
  max-width: 760px;
  height: 220px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.escritos-page .form-notice {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.escritos-page fieldset[aria-labelledby="saved-data-title"] {
  grid-column: 1 / -1;
}

.escritos-page fieldset[aria-labelledby="saved-data-title"] p,
.escritos-page fieldset[aria-labelledby="saved-data-title"] .tool-actions,
.escritos-page fieldset[aria-labelledby="saved-data-title"] .form-notice {
  grid-column: 1 / -1;
}

.escritos-page fieldset[aria-labelledby="saved-data-title"] .tool-actions {
  align-items: center;
  gap: .75rem;
}

.escritos-page fieldset[aria-labelledby="saved-data-title"] .tool-button {
  min-width: 11rem;
  width: auto;
  white-space: normal;
}

.escritos-page .preview-card {
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
  /* Ancla para el overlay del paywall (#driverDocsPaywall), que va
     position:absolute SOBRE la vista previa. */
  position: relative;
}

.escritos-page .document-preview {
  background: #fff;
  color: #111;
  border-radius: 8px;
  padding: 24px;
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: break-word;
  word-break: normal;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: hidden;
  /* Presentación tipo visor de documento: caja más grande con barra de scroll
     vertical, en vez de crecer indefinidamente empujando la página. */
  max-height: clamp(420px, 58vh, 640px);
  overflow-y: auto;
}

/* Contenido jurídico inyectado: que cada parrafo, tabla o imagen
   respete el ancho del contenedor en cualquier viewport. Para la prosa
   jurídica usamos word-break:normal + overflow-wrap:anywhere, que
   sólo parte cadenas sin separadores (URLs, identificadores largos)
   pero respeta palabras españolas para que la justificación tipográfica
   no produzca cortes a mitad de palabra. */
.escritos-page .document-preview *,
.escritos-page .document-preview p,
.escritos-page .document-preview strong,
.escritos-page .document-preview span {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
}

.escritos-page .document-preview pre,
.escritos-page .document-preview code {
  white-space: pre-wrap;
  overflow-x: auto;
  max-width: 100%;
}

.escritos-page .document-preview table {
  max-width: 100%;
  width: 100%;
  table-layout: fixed;
}

.escritos-page .document-preview img {
  max-width: 100%;
  height: auto;
}

.escritos-page .document-preview h3,
.escritos-page .document-preview h4 {
  color: #111;
}

.escritos-page .document-preview h3,
.escritos-page .document-preview h4,
.escritos-page .document-preview p,
.escritos-page .document-preview ol,
.escritos-page .document-preview ul {
  margin-top: 0;
  margin-bottom: 10px;
}

/* Justificación tipográfica para el cuerpo del escrito jurídico.
   Excluye encabezado destinatario, pie de documento y firma — esos
   bloques tienen reglas específicas que mantienen su alineación. */
.escritos-page .document-preview p,
.escritos-page .document-preview li {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  overflow-wrap: break-word;
  word-break: normal;
}

.escritos-page .document-preview .legal-recipient p,
.escritos-page .document-preview .document-footer p,
.escritos-page .document-preview .legal-sign,
.escritos-page .document-preview .legal-sign p {
  text-align: inherit;
  hyphens: none;
  -webkit-hyphens: none;
  -ms-hyphens: none;
}

.escritos-page .document-preview .document-data-block {
  margin: 12px 0;
}

.escritos-page .document-preview .document-data-block ul {
  display: grid;
  gap: 4px;
  list-style: none;
  padding-left: 0;
}

.escritos-page .document-preview .signature-image {
  display: block;
  width: 360px;
  max-width: 100%;
  height: auto;
  margin: 18px 0 6px;
  border-bottom: 1px solid #222;
}

/* === Bloque de firma sin canvas inline === */
/* El canvas #signatureCanvas está oculto vía atributo hidden + esta regla
   refuerzo. La firma se captura desde el modal y se previsualiza aquí. */
.escritos-page #signatureCanvas { display: none !important; }

.escritos-page .signature-preview-box {
  min-height: 96px;
  margin: 12px 0 16px;
  padding: 14px;
  background: #fff;
  border: 2px dashed rgba(11, 79, 159, 0.4);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #56627a;
  font-size: 0.95rem;
  box-sizing: border-box;
}
.escritos-page .signature-preview-box.has-signature {
  border-color: #0b4f9f;
  border-style: solid;
  padding: 8px;
}
.escritos-page .signature-preview-box .signature-preview-empty {
  font-style: italic;
}
.escritos-page .signature-preview-box img {
  display: block;
  max-width: 100%;
  max-height: 140px;
  height: auto;
  object-fit: contain;
}

/* === Modal de firma a pantalla completa ===
   En móvil y tablet ocupa 100 % de la pantalla.
   En desktop se centra ocupando ~50 % del ancho y ~80 % del alto. */
.signature-fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  flex-direction: column;
  padding: 14px;
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
/* Móvil y tablet hasta 980px: full screen sobre fondo claro. */
@media (max-width: 980px) {
  .signature-fullscreen-overlay {
    background: #eef2f7;
  }
}
/* Desktop: panel centrado al ~50 % de la pantalla. */
@media (min-width: 981px) {
  .signature-fullscreen-overlay {
    align-items: center;
    justify-content: center;
  }
  .signature-fullscreen-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
  }
  .signature-fullscreen-overlay > .signature-fs-header,
  .signature-fullscreen-overlay > .signature-fs-hint,
  .signature-fullscreen-overlay > .signature-fs-canvas-wrap,
  .signature-fullscreen-overlay > .signature-fs-actions {
    width: min(720px, 55vw);
    margin-left: auto;
    margin-right: auto;
    background: #eef2f7;
  }
  .signature-fullscreen-overlay > .signature-fs-header {
    border-radius: 10px 10px 0 0;
    padding: 14px 18px 4px;
  }
  .signature-fullscreen-overlay > .signature-fs-hint {
    padding: 0 18px 8px;
    margin: 0 auto;
  }
  .signature-fullscreen-overlay > .signature-fs-canvas-wrap {
    height: 50vh;
    min-height: 320px;
    max-height: 460px;
  }
  .signature-fullscreen-overlay > .signature-fs-actions {
    border-radius: 0 0 10px 10px;
    padding: 12px 18px 16px;
    background: #eef2f7;
  }
}

.signature-fullscreen-overlay .signature-fs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px;
}

.signature-fullscreen-overlay .signature-fs-header h3 {
  margin: 0;
  color: #1a2540;
  font-size: 1.15rem;
}

.signature-fullscreen-overlay .signature-fs-close {
  border: 0;
  background: transparent;
  color: #1a2540;
  font-size: 2rem;
  line-height: 1;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  cursor: pointer;
}
.signature-fullscreen-overlay .signature-fs-close:hover,
.signature-fullscreen-overlay .signature-fs-close:focus-visible {
  background: rgba(11, 79, 159, 0.1);
  outline: none;
}

.signature-fullscreen-overlay .signature-fs-hint {
  margin: 4px 6px 10px;
  color: #4a5568;
  font-size: 0.95rem;
  line-height: 1.45;
}

.signature-fullscreen-overlay .signature-fs-canvas-wrap {
  flex: 1;
  min-height: 0;
  background: #fff;
  border: 2px dashed #6b7d99;
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  box-sizing: border-box;
}

.signature-fullscreen-overlay .signature-fs-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}

.signature-fullscreen-overlay .signature-fs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 6px 0;
  justify-content: flex-end;
}

.signature-fullscreen-overlay .signature-fs-actions .tool-button {
  min-height: 52px;
  min-width: 130px;
  flex: 0 1 auto;
}

/* En móvil los botones ocupan más ancho y se alinean en columna si hace falta. */
@media (max-width: 600px) {
  .signature-fullscreen-overlay {
    padding: 10px;
  }
  .signature-fullscreen-overlay .signature-fs-actions {
    justify-content: stretch;
  }
  .signature-fullscreen-overlay .signature-fs-actions .tool-button {
    flex: 1 1 calc(33% - 8px);
    min-width: 0;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 0.85rem;
  }
}

/* El botón "Firmar a pantalla completa" más prominente en móvil. */
.escritos-page .signature-block-actions {
  margin-top: 10px;
}
@media (max-width: 600px) {
  .escritos-page .signature-block-actions {
    margin-top: 14px;
  }
  .escritos-page .signature-block-actions .tool-button {
    width: 100%;
    min-width: 0;
  }
}

.escritos-page .document-preview .signature-digital-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 64px;
  margin: 18px 0 0;
  padding: 14px 16px;
  border: 1.5px dashed #6b7d99;
  border-radius: 6px;
  background: rgba(11, 79, 159, 0.03);
  color: #56627a;
  font-size: 0.9rem;
  font-style: italic;
  text-align: center;
  box-sizing: border-box;
}

.escritos-page .document-preview .document-footer {
  margin-top: 12px;
  padding-top: 6px;
  border-top: 1px solid #ccc;
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
  color: #333;
}

.escritos-page .document-preview .document-footer p {
  margin: 0;
  white-space: normal;
  word-break: normal;
}

.escritos-page .document-preview .attachment-annex {
  page-break-before: always;
  margin-top: 28px;
}

.escritos-page .document-preview .attachment-annex img {
  max-width: 100%;
  height: auto;
}

@media (min-width: 780px) {
  .escritos-page fieldset {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }

  .escritos-page fieldset label {
    grid-column: span 6;
  }

  .escritos-page fieldset label:has(textarea),
  .escritos-page fieldset label:has(select),
  .escritos-page fieldset .writing-radio-group,
  .escritos-page fieldset .writing-attachments,
  .escritos-page #dynamicFields label {
    grid-column: 1 / -1;
  }

  .escritos-page fieldset label:has([name="workerPostalCode"]),
  .escritos-page fieldset label:has([name="companyPostalCode"]) {
    grid-column: span 3;
  }

  .escritos-page fieldset label:has([name="workerCity"]),
  .escritos-page fieldset label:has([name="companyCity"]) {
    grid-column: span 6;
  }

  .escritos-page fieldset label:has([name="workerProvince"]),
  .escritos-page fieldset label:has([name="companyProvince"]) {
    grid-column: span 3;
  }

  .escritos-page fieldset label:has([name="companyAddressExtra"]) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .escritos-page fieldset[aria-labelledby="saved-data-title"] .tool-button {
    width: 100%;
  }

  .escritos-page #addAttachmentFiles {
    justify-self: stretch;
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .escritos-page .document-preview {
    padding: 14px;
    font-size: 13.5px;
  }

  .escritos-page .tool-card,
  .escritos-page .tool-info,
  .escritos-page .signature-block {
    padding: 14px;
  }

  .escritos-page .signature-block canvas {
    height: 140px;
  }

  /* En pantallas pequeñas la tarjeta del paywall ocupa casi todo el ancho.
     (El paywall #driverDocsPaywall es HERMANO del preview, no descendiente:
     se apunta por ID, no con `is-locked-preview .driver-docs-paywall`.) */
  #driverDocsPaywall .driver-docs-paywall-card {
    max-width: 100%;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm 14mm;
  }

  html,
  body {
    background: #fff !important;
  }

  body.escritos-page > :not(main),
  body.escritos-page main > :not(.preview-card),
  body.escritos-page .preview-card > :not(#documentPreview) {
    display: none !important;
  }

  body.escritos-page main,
  body.escritos-page .preview-card,
  #documentPreview {
    display: block !important;
    background: #fff !important;
    color: #111 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
  }

  #documentPreview {
    border-radius: 0;
    /* En impresión el escrito va completo: anula el visor con scroll de pantalla
       (incluida la ventana de altura fija de ds-paywall.css). */
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    font-size: 10.8pt;
    line-height: 1.3;
  }

  #documentPreview h3 {
    font-size: 13pt;
    line-height: 1.2;
  }

  #documentPreview h4 {
    font-size: 11.2pt;
    line-height: 1.2;
  }

  #documentPreview p,
  #documentPreview ol,
  #documentPreview ul {
    margin-bottom: 6pt;
  }

  #documentPreview .document-data-block {
    margin: 7pt 0;
  }

  #documentPreview .signature-image {
    width: 85mm;
    margin: 10pt 0 4pt;
  }

  #documentPreview .signature-digital-box {
    width: 100%;
    min-height: 16mm;
    margin: 10pt 0 0;
    padding: 6pt 8pt;
    border: 1pt dashed #555;
    border-radius: 3pt;
    color: #333;
    font-size: 9pt;
    font-style: italic;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #documentPreview .document-footer {
    margin-top: 6pt;
    padding-top: 3pt;
    font-size: 7.8pt;
    line-height: 1.1;
    text-align: center;
    color: #333;
  }

  #documentPreview .document-footer p {
    margin: 0;
    white-space: normal;
    word-break: normal;
  }

  #documentPreview .attachment-annex {
    page-break-before: auto;
    break-before: auto;
    margin-top: 8pt;
  }
}

.escritos-form .driver-field-missing,
.escritos-form label.driver-field-missing input,
.escritos-form label.driver-field-missing select,
.escritos-form label.driver-field-missing textarea {
  outline: 2px solid #dc2626 !important;
  outline-offset: 2px;
  background: #fff5f5 !important;
}
.escritos-form label.driver-field-missing { color: #991b1b; }

/* === Driver Lex: 4 bloques en rejilla 2×2 (mismo tamaño) ===================
   Igual criterio que Driver Tacho.  La página se organiza en 4 tarjetas del
   mismo tamaño, agrupadas por lógica de uso:
     Fila 1 (ENTRADA):    [Datos para la consulta] [Mis consultas en la nube]
     Fila 2 (CONSULTA):   [Consulta a Driver Lex]  [Respuesta de Driver Lex]
   El <form id="driverLexForm"> envuelve las tarjetas Datos y Consulta pero usa
   display:contents para no generar caja: así sus dos <section> participan
   directamente en la rejilla del workspace SIN romper el envío del formulario.
   (Si editas esto, BUMPEA el ?v= de escritos-laborales.css.) */
@media (min-width: 1024px) {
  /* product.css fija width+max-width en main.container; subimos AMBOS al ancho
     de datos para que quepan dos columnas cómodas. */
  body.driver-lex-page main.container { width: min(100% - var(--ds-gx), var(--ds-max-data)) !important; max-width: var(--ds-max-data) !important; }
}
.driver-lex-page .dlx-form { display: contents !important; }
.driver-lex-page .dlx-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}
/* Las tarjetas Datos / Consulta apilan sus fieldsets con separación uniforme
   (antes ese gap lo daba el grid del propio form). */
.driver-lex-page #dlxDatos,
.driver-lex-page #dlxConsulta { display: flex; flex-direction: column; gap: 16px; }
/* La nube pierde el límite/centrado de .ds-container dentro del workspace. */
.driver-lex-page #driver-lex-archive-section {
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
}
@media (min-width: 1024px) {
  .driver-lex-page .dlx-workspace {
    grid-template-columns: 1fr 1fr;
    column-gap: 22px;
  }
  /* Rejilla 2×2 por áreas (el <form> es display:contents, así que las cuatro
     secciones son ítems directos del grid).  Orden DOM = orden en móvil:
     Datos → Consulta → Respuesta → Nube.  En escritorio se recolocan:
     fila 1 [Datos | Consulta] · fila 2 [Nube | Respuesta]. */
  .driver-lex-page #dlxDatos { grid-column: 1; grid-row: 1; }
  .driver-lex-page #dlxConsulta { grid-column: 2; grid-row: 1; }
  .driver-lex-page #driver-lex-archive-section { grid-column: 1; grid-row: 2; }
  .driver-lex-page .preview-card { grid-column: 2; grid-row: 2; }

  /* "Consulta a Driver Lex" iguala su altura a "Datos para la consulta":
     el workspace usa align-items:start (no estira), así que forzamos el
     estirado de este bloque a la altura de la fila y montamos una cadena flex
     para que el textarea de la consulta absorba el espacio sobrante. */
  .driver-lex-page #dlxConsulta { align-self: stretch; }
  .driver-lex-page #dlxConsulta .driver-lex-query {
    display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto;
  }
  .driver-lex-page #dlxConsulta .driver-lex-query > label:nth-of-type(2) {
    display: flex; flex-direction: column; gap: 6px; flex: 1 1 auto;
  }
  .driver-lex-page #dlxConsulta .driver-lex-query > label:nth-of-type(2) > #driverLexQuery {
    flex: 1 1 auto; height: auto;
  }
}

/* === Driver Docs: 4 bloques en 2 columnas independientes (flex) =============
   Columna izquierda: [Tus datos] → [Mis documentos en la nube]
   Columna derecha:   [El escrito] → [Vista previa del escrito]
   Dos columnas flex separadas (no un grid 2×2) para que el hueco vertical entre
   los bloques de cada columna sea SIEMPRE el mismo (20px): con un grid las filas
   comparten altura entre columnas y los huecos salían desiguales.
   El <form id="escritosForm"> usa display:contents para no romper la generación
   del escrito; sus dos <div.ddx-col> participan directamente en el flex. */
.driver-docs-page .ddx-form { display: contents !important; }
.driver-docs-page .ddx-workspace {
  width: min(100% - var(--ds-gx), var(--ds-max-data));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.driver-docs-page .ddx-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.driver-docs-page #ddxDatos,
.driver-docs-page #ddxEscrito { display: flex; flex-direction: column; gap: 16px; }
.driver-docs-page .ddx-block { width: 100% !important; max-width: none !important; margin: 0 !important; }
/* "Mis documentos en la nube" (.dtax-account-section) trae margin:18px auto!important
   de la regla inline/cloud-access; lo anulamos para que el único espaciado entre
   bloques sea el gap:20px de la columna. */
.driver-docs-page .ddx-workspace .dtax-account-section { margin: 0 !important; }
@media (min-width: 1024px) {
  body.driver-docs-page main.container { width: min(100% - var(--ds-gx), var(--ds-max-data)) !important; max-width: var(--ds-max-data) !important; }
  .driver-docs-page .ddx-workspace { flex-direction: row; gap: 20px; align-items: flex-start; }
  .driver-docs-page .ddx-col { flex: 1 1 0; }
}

#documentPreview.is-locked-preview {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}
/* Contenido bloqueado (pre-pago): desenfocado y no seleccionable, para que se
   vea la FORMA del escrito (tipo paywall) sin poder leerlo del todo.  El
   paywall #driverDocsPaywall es HERMANO del preview (no hijo), por lo que NO
   recibe este blur: su tarjeta se ve nítida encima. */
#documentPreview.is-locked-preview > * {
  filter: blur(3px);
  pointer-events: none;
  user-select: none;
}
/* ═══════════════════════════════════════════════════════════════════════════
   PAYWALL DOCS — overlay SOBRE la vista previa (decisión de producto 2026-06-04).
   ───────────────────────────────────────────────────────────────────────────
   El cliente lo quiere ENCIMA de la vista previa, no debajo.  El
   #driverDocsPaywall se inserta como HERMANO del #documentPreview dentro de
   .preview-card (renderLockedPreview → insertAdjacentElement("afterend")) y se
   posiciona ABSOLUTO, centrado, sobre la vista previa.  El contenido del
   preview va DESENFOCADO (blur) detrás; la tarjeta, nítida, encima.
   pointer-events:none en el contenedor deja pasar el scroll al preview; la
   tarjeta interior recupera pointer-events:auto para ser clicable.
   (Si editas esta CSS, BUMPEA el ?v= en driver-docs.html.) */
#driverDocsPaywall {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  /* Cubre la parte baja de la vista previa (no el título de arriba): el
     escrito se desvanece y la tarjeta de desbloqueo queda ENCIMA. */
  height: 74%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
  margin: 0;
  padding: 16px;
  box-sizing: border-box;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, .72) 38%, rgba(255, 255, 255, .94) 100%);
}
#driverDocsPaywall .driver-docs-paywall-card {
  pointer-events: auto;
}
#driverDocsPaywall .driver-docs-paywall-card:focus-within {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

/* === Pareja de CTAs "Subir archivo" + "Hacer foto" lado a lado ====
   La clase modificadora hace que ambos botones ocupen el ancho
   completo del fieldset (escapando del grid de 2 columnas) y se
   muestren en linea. En mobile se apilan al 100% como el resto. */
.escritos-page .tool-actions.tool-actions--upload {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.escritos-page .tool-actions.tool-actions--upload > .tool-button {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
}

@media (max-width: 520px) {
  .escritos-page .tool-actions.tool-actions--upload > .tool-button {
    flex: 1 1 100%;
    width: 100%;
  }
}

/* === Formato escrito jurídico (estilo profesional) ============== */
.escritos-page #documentPreview .legal-recipient {
  text-align: right;
  margin: 0 0 24px;
}
.escritos-page #documentPreview .legal-recipient p {
  margin: 0;
  line-height: 1.45;
}
.escritos-page #documentPreview .legal-subject {
  margin: 18px 0;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.55;
}
.escritos-page #documentPreview .legal-intro,
.escritos-page #documentPreview .legal-body {
  margin: 14px 0;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.65;
  text-indent: 0;
}
.escritos-page #documentPreview .legal-section {
  margin: 22px 0 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.escritos-page #documentPreview .legal-ordinal {
  margin: 0 0 14px;
  line-height: 1.65;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  overflow-wrap: break-word;
  word-break: normal;
}
.escritos-page #documentPreview .legal-documents {
  margin: 4px 0 18px 0;
  padding-left: 24px;
  line-height: 1.55;
}
.escritos-page #documentPreview .legal-documents li {
  margin: 0 0 4px 0;
}
.escritos-page #documentPreview .legal-extra-facts > * {
  margin: 0 0 14px;
  line-height: 1.65;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  overflow-wrap: break-word;
  word-break: normal;
}
.escritos-page #documentPreview .legal-closing {
  margin: 24px 0 6px;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  overflow-wrap: break-word;
  word-break: normal;
}
.escritos-page #documentPreview .legal-sign {
  margin: 6px 0 0;
}
.escritos-page #documentPreview .signature-image {
  display: block;
  margin: 18px 0 6px;
  max-width: 360px;
  width: 100%;
  height: auto;
}

/* ===== Bloque prepago compartido (Driver Lex / Driver Docs) =====
   Mismo look que la paywall de Driver Tacho (.dtf-paywall-card)
   para coherencia visual entre productos. */
.driver-lex-paywall,
.driver-docs-paywall {
  position: relative;
  z-index: 2;
  margin-top: 18px;
}
.driver-lex-paywall-card,
.driver-docs-paywall-card {
  margin: 0 auto;
  padding: 22px 24px;
  max-width: 520px;
  background: #fff;
  border: 1px solid #0b4f9f;
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(11, 79, 159, .18);
}
.driver-lex-paywall-card h3,
.driver-docs-paywall-card h3 {
  margin: 0 0 8px;
  color: #0b4f9f;
}
.driver-lex-paywall-card p,
.driver-docs-paywall-card p {
  margin: 0 0 12px;
  color: #1a2540;
  line-height: 1.5;
}
.driver-lex-paywall-price,
.driver-docs-paywall-price {
  margin: 12px 0 4px !important;
  padding: 8px 12px;
  background: #eff6ff;
  border-radius: 8px;
  color: #0b4f9f;
  font-weight: 700;
}
.driver-lex-paywall-vat,
.driver-docs-paywall-vat,
.driver-docs-payment-vat {
  margin: 0 0 16px !important;
  color: #56627a;
  font-size: .82rem;
  font-style: italic;
  text-align: center;
}
