:root {
  --app-bg: #070b11;
  --app-bg-2: #101720;
  --app-text: #f5f7fb;

  --primary: #0e3a5b;
  --primary-dark: #08283f;
  --line: #d7dee7;
  --soft: #f5f7fa;
  --paper: #ffffff;
  --text: #1e2933;
  --muted: #5f6b76;
  --white: #ffffff;
  --danger: #d93025;
  --danger-dark: #b3261e;
}

* {
  box-sizing: border-box;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 88% 12%, rgba(174, 24, 30, 0.22), transparent 26%),
    linear-gradient(180deg, var(--app-bg) 0%, var(--app-bg-2) 100%);
  color: var(--app-text);
}

.page {
  width: 100%;
  min-height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.actions {
  width: 100%;
  max-width: 1180px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.actions .btn-secondary,
.actions .back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  height: 44px;
  padding: 0 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: 0.2s ease;
  border: none;
  font-family: inherit;
  color: #ffffff;
}

.actions .btn-secondary {
  background: #0f4c81;
  box-shadow: 0 12px 24px rgba(15, 76, 129, 0.25);
}

.actions .btn-secondary:hover {
  background: #12619f;
  transform: translateY(-2px);
}

.actions .back-btn {
  background: linear-gradient(90deg, #e32d34 0%, #9f1119 100%);
  box-shadow: 0 12px 24px rgba(180, 20, 28, 0.25);
}

.actions .back-btn:hover {
  background: linear-gradient(90deg, #f03941 0%, #b5151e 100%);
  transform: translateY(-2px);
}

button {
  border: 0;
  cursor: pointer;
  font-family: inherit;
}

.mensaje-error {
  width: 100%;
  max-width: 1180px;
  margin: 0 0 14px 0;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(217, 48, 37, 0.14);
  border: 1px solid rgba(217, 48, 37, 0.35);
  color: #ff9a9a;
  font-size: 14px;
  font-weight: 800;
}

.oculto {
  display: none;
}

form {
  width: 100%;
  display: flex;
  justify-content: center;
}

.sheet {
  width: min(216mm, 100%);
  min-height: 279mm;
  background: var(--paper);
  color: var(--text);
  border: 1px solid #d7dee7;
  border-radius: 12px;
  padding: 12mm;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 30px 80px rgba(0, 0, 0, 0.42);
  position: relative;
  overflow: hidden;
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(14, 58, 91, 0.08);
  border-radius: 8px;
  pointer-events: none;
}

.header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.brand-small {
  margin-bottom: 8px;
}

.brand-small p {
  color: #111827 !important;
  font-size: 12px !important;
  font-weight: 800 !important;
  margin: 0 !important;
}

.brand-small select,
.brand-small input {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
  min-width: 320px;
  max-width: 100%;
  font-family: inherit;
}

.title {
  margin: 10px 0 0;
  color: var(--primary);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.4px;
  line-height: 1.15;
}

.title-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.folio-input {
  width: 180px;
  border: none;
  border-bottom: 2px solid var(--primary);
  font-size: 25px;
  font-weight: 900;
  color: var(--primary);
  background: transparent;
  padding: 2px 4px;
}

.folio-input:focus {
  outline: none;
}

.header-right {
  text-align: right;
  min-width: 240px;
}

.logo-box-column {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.logo-licman {
  max-width: 180px;
  height: auto;
  object-fit: contain;
}

.logo-info {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 14px;
  font-weight: 900;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 5px;
  border-bottom: 1px solid #e4eaf0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label,
.resumen-row label,
.resumen-final-row label {
  font-size: 11px;
  font-weight: 800;
  color: #415061;
}

.field input,
.field select,
.field textarea,
.resumen-row input,
.resumen-row select,
.resumen-final-row input {
  width: 100%;
  border: 1px solid #cdd6e1;
  border-radius: 9px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  padding: 8px 11px;
  font-family: inherit;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.resumen-row input:focus,
.resumen-row select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 58, 91, 0.10);
}

.field textarea {
  resize: vertical;
  min-height: 86px;
}

.inline-input {
  width: 100%;
}


/* ===== BUSCADOR DE CLIENTES REALES ===== */

.cliente-selector-field {
  position: relative;
  z-index: 40;
}

.cliente-buscador {
  position: relative;
}

.cliente-resultados {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: 0;
  z-index: 1200;
  max-height: 280px;
  overflow-y: auto;
  padding: 7px;
  border: 1px solid #c9d5e1;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 18px 45px rgba(7, 11, 17, 0.20);
}

.cliente-resultado-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 11px;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 0.15s ease, transform 0.15s ease;
}

.cliente-resultado-item:hover,
.cliente-resultado-item:focus {
  outline: none;
  background: #edf4fa;
  transform: translateY(-1px);
}

.cliente-resultado-nombre {
  font-size: 12px;
  font-weight: 900;
  color: #0e3a5b;
}

.cliente-resultado-detalle {
  font-size: 10px;
  font-weight: 700;
  color: #6b7783;
}

.cliente-resultados-vacio {
  padding: 13px 11px;
  color: #6b7783;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.cliente-seleccionado-badge {
  margin-top: 6px;
  min-height: 27px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid #bad6c4;
  border-radius: 9px;
  background: #edf8f1;
  color: #1f6b3b;
  font-size: 10px;
  font-weight: 900;
}

.cliente-seleccionado-punto {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #2f9e57;
  box-shadow: 0 0 0 3px rgba(47, 158, 87, 0.14);
}

#clienteSeleccionadoTexto {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#limpiarClienteSeleccionado {
  width: 21px;
  height: 21px;
  flex: 0 0 21px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(31, 107, 59, 0.10);
  color: #1f6b3b;
  font-size: 16px;
  line-height: 1;
}

#limpiarClienteSeleccionado:hover {
  background: rgba(31, 107, 59, 0.18);
}

.cliente-resultados.oculto,
.cliente-seleccionado-badge.oculto {
  display: none !important;
}

.pdf-mode-single .cliente-resultados,
.pdf-mode-single .cliente-seleccionado-badge {
  display: none !important;
}

.hidden-field {
  display: none;
}

.oc-box {
  border: 1px solid #d7dee7;
  background: #f5f7fa;
  border-radius: 12px;
  padding: 12px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.oc-row {
  display: grid;
  grid-template-columns: 120px 18px 1fr;
  align-items: start;
  gap: 6px;
  font-size: 13px;
}

.oc-label {
  font-weight: 800;
  color: var(--text);
}

.oc-sep {
  text-align: center;
  color: var(--muted);
}

.oc-value {
  color: var(--text);
}

.resumen-tabla {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

.resumen-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.resumen-total input,
.resumen-final-row.total input {
  font-weight: 900;
}

.resumen-final {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  background: #f5f7fa;
  border: 1px solid #d7dee7;
  border-radius: 14px;
  padding: 14px;
}

.resumen-final-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  gap: 10px;
}

.resumen-final-row input {
  background: #ffffff;
}

.resumen-final-row.total input {
  background: #eaf1f8;
  border-color: #b9ccdd;
  color: var(--primary);
  font-size: 15px;
}

.firma-section {
  margin-top: 8px;
}

.firma-vendedor-box {
  border: 1px solid #d7dee7;
  border-radius: 12px;
  background: #ffffff;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.firma-linea-box {
  margin-top: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.firma-linea-real {
  width: 220px;
  max-width: 100%;
  border-top: 2px solid #23313d;
}

.firma-linea-texto {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
}

input[readonly],
textarea[readonly] {
  background: #f3f6f8;
  color: #4a5560;
}

.input-error {
  border-color: #d93025 !important;
  box-shadow: 0 0 0 3px rgba(217, 48, 37, 0.12) !important;
}

@media (max-width: 900px) {
  .sheet {
    width: 100%;
    min-height: auto;
    padding: 28px;
  }

  .grid-2,
  .resumen-tabla {
    grid-template-columns: 1fr;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-right,
  .logo-box-column {
    align-items: flex-start;
    text-align: left;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 14px;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions .btn-secondary,
  .actions .back-btn {
    width: 100%;
  }

  .sheet {
    padding: 20px;
    border-radius: 10px;
  }

  .title {
    font-size: 18px;
  }

  .folio-input {
    width: 120px;
    font-size: 20px;
  }

  .brand-small select,
  .brand-small input {
    min-width: 0;
    width: 100%;
  }

  .resumen-final-row {
    grid-template-columns: 1fr;
  }

  .oc-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

/* ===== IMPRESIÓN / PDF ===== */

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    height: 297mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    overflow: hidden !important;
  }

  .page {
    width: 210mm;
    height: 297mm;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
  }

  .actions,
  .mensaje-error {
    display: none !important;
  }

  form {
    width: 210mm;
    height: 297mm;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
  }

  .sheet {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 6mm 7mm !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }

  .sheet::before {
    display: none !important;
  }
}

/* ===== MODO PDF COMPACTO UNA SOLA HOJA ===== */

.pdf-mode-single {
  width: 210mm !important;
  min-height: 297mm !important;
  height: auto !important;
  margin: 0 !important;
  padding: 6mm 7mm !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
}

.pdf-mode-single::before {
  display: none !important;
}

.pdf-mode-single .grid-2,
.pdf-mode-single .resumen-tabla {
  grid-template-columns: 1fr 1fr !important;
  gap: 6px 10px !important;
}

.pdf-mode-single .content {
  gap: 8px !important;
}

.pdf-mode-single .section {
  gap: 5px !important;
}

.pdf-mode-single .section-title {
  font-size: 10.5px !important;
  padding-bottom: 2px !important;
  margin: 0 !important;
}

.pdf-mode-single .header {
  padding-bottom: 7px !important;
  margin-bottom: 8px !important;
  gap: 14px !important;
}

.pdf-mode-single .title {
  font-size: 17px !important;
  margin-top: 5px !important;
  line-height: 1.05 !important;
}

.pdf-mode-single .folio-input {
  width: 120px !important;
  font-size: 19px !important;
}

.pdf-mode-single .brand-small {
  margin-bottom: 4px !important;
}

.pdf-mode-single .brand-small p {
  font-size: 9.5px !important;
}

.pdf-mode-single .logo-licman {
  max-width: 135px !important;
}

.pdf-mode-single .logo-info {
  font-size: 8.5px !important;
}

.pdf-mode-single .field {
  gap: 2px !important;
}

.pdf-mode-single .field label,
.pdf-mode-single .resumen-row label,
.pdf-mode-single .resumen-final-row label {
  font-size: 8px !important;
}

.pdf-mode-single .field input,
.pdf-mode-single .field select,
.pdf-mode-single .field textarea,
.pdf-mode-single .resumen-row input,
.pdf-mode-single .resumen-row select,
.pdf-mode-single .resumen-final-row input {
  font-size: 9.5px !important;
  padding: 3.5px 6px !important;
  border-radius: 5px !important;
  min-height: 22px !important;
}

.pdf-mode-single .field textarea {
  min-height: 55px !important;
}

.pdf-mode-single .oc-box {
  padding: 6px 8px !important;
  gap: 3px !important;
  border-radius: 8px !important;
}

.pdf-mode-single .oc-row {
  font-size: 9.5px !important;
  grid-template-columns: 82px 10px 1fr !important;
  gap: 4px !important;
}

.pdf-mode-single .resumen-row {
  gap: 2px !important;
}

.pdf-mode-single .resumen-final {
  margin-top: 5px !important;
  padding: 7px !important;
  gap: 4px !important;
  border-radius: 9px !important;
}

.pdf-mode-single .resumen-final-row {
  grid-template-columns: 80px 1fr !important;
  gap: 6px !important;
}

.pdf-mode-single .resumen-final-row.total input {
  font-size: 11px !important;
}

.pdf-mode-single .firma-section {
  margin-top: 3px !important;
}

.pdf-mode-single .firma-vendedor-box {
  padding: 7px !important;
  gap: 4px !important;
  border-radius: 8px !important;
}

.pdf-mode-single .firma-linea-box {
  margin-top: 3px !important;
  gap: 3px !important;
}

.pdf-mode-single .firma-linea-real {
  width: 170px !important;
}

.pdf-mode-single .firma-linea-texto {
  font-size: 8px !important;
}

/* ===== TEXTO QUE REEMPLAZA INPUTS EN PDF ===== */

.pdf-control-text {
  width: 100%;
  min-height: 22px;
  display: flex;
  align-items: center;
  padding: 3.5px 6px;
  border: 1px solid #cdd6e1;
  border-radius: 5px;
  background: #ffffff;
  color: #111827;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
}

.pdf-mode-single .resumen-row .pdf-control-text {
  background: #ffffff;
}

.pdf-mode-single .resumen-final .pdf-control-text {
  font-weight: 800;
  background: #ffffff;
}

.pdf-mode-single .resumen-final-row.total .pdf-control-text {
  color: #0e3a5b;
  font-weight: 900;
  background: #eaf1f8;
  border-color: #b9ccdd;
}

/* ===== VALIDACIÓN PDF ===== */

.required-error {
  border-color: #d93025 !important;
  box-shadow: 0 0 0 2px rgba(217, 48, 37, 0.16) !important;
}

.required-error-wrapper {
  border-radius: 8px;
}

.alerta-validacion,
.mensaje-error {
  width: min(210mm, 100%);
  margin: 0 auto 14px;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(217, 48, 37, 0.14);
  border: 1px solid rgba(217, 48, 37, 0.35);
  color: #ff9a9a;
  font-size: 14px;
  font-weight: 800;
}

.alerta-validacion strong,
.mensaje-error strong {
  display: block;
  color: #ffffff;
  margin-bottom: 4px;
}

/* ===== MARCO VISUAL APP DOCUMENTOS ===== */

.page {
  width: 100%;
  min-height: 100vh;
  padding: 24px 20px 40px;
}

.document-frame {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.document-topbar {
  width: 100%;
  margin: 0 0 22px 0;
  background: rgba(16, 23, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 30px;
  padding: 26px 30px;
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.42);
  position: relative;
  overflow: hidden;
}

.document-topbar::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top right, rgba(217, 39, 48, 0.24), transparent 32%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04), transparent 45%);
  pointer-events: none;
}

.document-topbar-content {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 28px;
  align-items: center;
}

.document-topbar .brand-block h1 {
  margin: 0 0 12px;
  color: #ffffff;
  font-size: clamp(1.8rem, 2.8vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -0.5px;
  font-weight: 900;
}

.document-topbar .brand-block p {
  margin: 0;
  color: #aeb7c6;
  font-size: 1.05rem;
}

.document-topbar .logo-box {
  background: #ffffff;
  border-radius: 24px;
  padding: 18px;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.document-topbar .logo-box img {
  max-width: 240px;
  max-height: 90px;
  object-fit: contain;
}

.document-body-card {
  width: 100%;
  background: rgba(7, 14, 24, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 32px;
  padding: 26px 28px 30px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.document-body-card .actions {
  width: min(210mm, 100%);
  margin: 0 auto 18px;
}

.document-body-card form {
  width: 100%;
  display: flex;
  justify-content: center;
}

.document-body-card .sheet {
  margin: 0 auto;
}

@media (max-width: 900px) {
  .document-topbar-content {
    grid-template-columns: 1fr;
  }

  .document-topbar .logo-box {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 0;
  }

  .document-frame {
    max-width: 100%;
  }

  .document-topbar {
    border-radius: 0 0 28px 28px;
    margin-bottom: 18px;
  }

  .document-topbar .brand-block h1 {
    font-size: 1.8rem;
  }

  .document-body-card {
    border-radius: 28px 28px 0 0;
    padding: 18px 14px 24px;
  }
}

@media print {
  .document-topbar,
  .document-body-card > .actions {
    display: none !important;
  }

  .document-frame,
  .document-body-card {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
}

/* ===== CORRECCIÓN TEXTO PDF ===== */

.pdf-control-text {
  width: 100%;
  min-height: 21px;
  border: 1px solid #cdd6e1;
  border-radius: 5px;
  background: #ffffff;
  color: #1e2933;
  font-size: 9px;
  font-weight: 500;
  line-height: 1.2;
  padding: 3px 6px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  white-space: nowrap;
  box-sizing: border-box;
}

.pdf-control-textarea {
  min-height: 42px;
  white-space: pre-wrap;
  align-items: flex-start;
}

.pdf-control-readonly {
  background: #f3f6f8;
  color: #4a5560;
}

.title-inline .pdf-control-text {
  width: 118px;
  min-height: 25px;
  border: none;
  border-bottom: 2px solid #0e3a5b;
  border-radius: 0;
  background: transparent;
  color: #0e3a5b;
  font-size: 18px;
  font-weight: 900;
  justify-content: center;
  padding: 0 3px;
}

.resumen-final-row .pdf-control-text {
  background: #ffffff;
}

.resumen-final-row.total .pdf-control-text {
  background: #eaf1f8;
  border-color: #b9ccdd;
  color: #0e3a5b;
  font-weight: 900;
}