/* =========================================================
   MODAL PREVISUALIZACIÓN DE REMISIÓN / DOCUMENTO
========================================================= */

#modal-vista-documento[hidden] {
  display: none !important;
}

#modal-vista-documento {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
}

#modal-vista-documento.mostrar {
  display: flex;
}

#modal-vista-documento .modal-content.modal-prev {
  width: min(900px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.modal-prev-top {
  display: flex;
  justify-content: flex-end;
  padding: 8px 12px 0;
}

.cerrar-modal-previsualizar {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background-color 0.2s;
}
.cerrar-modal-previsualizar:hover {
  background-color: rgba(0, 0, 0, 0.06);
}

.modal-prev-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 20px 10px;
  border-bottom: 1px solid #e5e7eb;
}
.prev-tab {
  padding: 8px 16px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s;
}
.prev-tab:hover {
  border-color: var(--color-primario, #00aaaa);
  color: var(--color-primario, #00aaaa);
}
.prev-tab.activo {
  background: var(--color-primario, #00aaaa);
  color: #fff;
  border-color: var(--color-primario, #00aaaa);
  font-weight: 600;
}

#contenido-documento {
  width: 100%;
  box-sizing: border-box;
  flex: 1;
}

.modal-prev-acciones {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
}
.btn-primario {
  background: var(--color-primario, #00aaaa);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primario:hover { background: var(--color-secundario, #008888); }
.btn-secundario {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secundario:hover { background: #e5e7eb; }
.modal-prev-acciones .btn-editar-modal {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.2s;
}
.modal-prev-acciones .btn-editar-modal:hover { background: #f3f4f6; }

@media print {
  #modal-vista-documento {
    position: static !important;
    background: none !important;
    padding: 0 !important;
    display: block !important;
  }
  #modal-vista-documento .modal-content.modal-prev {
    box-shadow: none !important;
    border-radius: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .modal-prev-top, .modal-prev-tabs, .modal-prev-acciones { display: none !important; }
  #contenido-documento { padding: 0 !important; }
}

/* =========================================================
   CONTENIDO DEL DOCUMENTO
========================================================= */

.modal-prev-contenido {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  color: #1f2937;
  background: #fff;
  padding: 24px 32px 28px;
  line-height: 1.5;
  box-sizing: border-box;
  width: 100%;
}

.modal-prev-datos-empresa {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 2px solid var(--color-primario, #ccc);
  padding-bottom: 10px;
  margin-bottom: 10px;
}
.modal-prev-logo-wrapper { display:flex; align-items:center; gap:14px; flex:1; }
.modal-prev-logo { width: 150px; flex: 0 0 150px; display:flex; align-items:center; }
.modal-prev-logo img { width: 100%; height: auto; display: block; }
.modal-prev-info { flex: 1; display:flex; flex-direction:column; justify-content:center; }
.modal-prev-info h2 {
  margin: 0 0 4px; font-size: 25px; color: var(--color-primario, #1f2937); font-weight: 700;
}
.modal-prev-info p, .modal-prev-contacto {
  margin: 0; font-size: 16px; color: #4b5563; line-height: 1.4;
}
.modal-prev-contacto { text-align: right; max-width: 260px; }
.modal-prev-contacto p { margin: 0; font-size: 16px; }
.modal-prev-contacto a { color: var(--color-primario, #1f2937); text-decoration: none; }

.modal-prev-datos {
  display: flex; gap: 28px; padding: 8px 0 10px; margin-bottom: 8px; font-size: 16px;
}
.modal-prev-datos > div { flex: 1; }
.modal-prev-datos p { margin: 1px 0; line-height: 1.35; font-size: 16px; }
.modal-prev-datos strong { color: #111827; }

.modal-prev-tabla { margin-top: 8px; border: 1px solid #d1d5db; }
.modal-prev-tabla table { width: 100%; border-collapse: collapse; font-size: 16px; }
.modal-prev-tabla th {
  background: var(--color-primario, #00aaaa); color: #fff; font-weight: 600;
  padding: 7px 6px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.3);
  font-size: 16px;
}
.modal-prev-tabla td {
  padding: 6px; border-bottom: 1px solid #f3f4f6; vertical-align: top; font-size: 16px;
}
.modal-prev-tabla tbody tr:last-child td { border-bottom: none; }
#td-item-prev, #td-cant-prev { text-align: center; white-space: nowrap; }
#td-und-prev, #td-total-prev { text-align: right; white-space: nowrap; }

.modal-prev-resumen {
  display: flex; align-items: stretch; margin-top: 12px;
  font-weight: 600; font-size: 16px; justify-content: flex-end;
}
.modal-prev-nota { flex: 1; }
.modal-prev-nota p {
  font-size: 13px; color: #6b7280; line-height: 1.5;
  padding-right: 18px; margin: 0; font-weight: 400;
}
.modal-prev-labels { flex: 0 0 110px; }
.modal-prev-labels p {
  margin: 0; padding: 6px 12px; text-align: right;
  border-bottom: 1px solid #e5e7eb; border-right: 1px solid #e5e7eb;
  font-size: 16px;
}
.modal-prev-valores { flex: 0 0 140px; }
.modal-prev-valores p {
  margin: 0; padding: 6px 12px; text-align: right;
  border-bottom: 1px solid #e5e7eb; font-size: 16px;
}

.modal-prev-derecha { text-align: right; }
.modal-prev-centro { text-align: center; }
.modal-prev-negrita { font-weight: 600; }

@media (max-width: 768px) {
  #modal-vista-documento { padding: 12px; }
  #modal-vista-documento .modal-content { max-height: 92vh; padding: 14px; border-radius: 10px; }
  .modal-prev-contenido { padding: 10px; font-size: 14px; }
  .modal-prev-datos-empresa, .modal-prev-datos, .modal-prev-resumen { flex-direction: column; align-items: stretch; }
  .modal-prev-logo, .modal-prev-contacto, .modal-prev-datos > div, .modal-prev-labels, .modal-prev-valores {
    width: 100%; max-width: 100%; flex: 1 1 100%;
  }
  .modal-prev-tabla { overflow-x: auto; }
  .modal-prev-tabla table { min-width: 700px; }
  .modal-prev-nota p { padding-right: 0; margin-bottom: 10px; }
}
