:root {
  --blue: #29aae1;
  --blue-dark: #1a4fa0;
  --gray-label: #d9d9d9;
  --gray-line: #cfcfcf;
  --text: #1a1a1a;
  --bg: #f2f4f7;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

button:disabled,
button:disabled:hover {
  background: #d5d9df !important;
  color: #9aa0a8 !important;
  border-color: #d5d9df !important;
  cursor: not-allowed !important;
}

.menu-btn:disabled,
.menu-btn:disabled:hover {
  background: transparent !important;
  color: #b8bcc3 !important;
  border-bottom-color: transparent !important;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 3px solid var(--blue);
}

.brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-logo {
  display: block;
  height: 52px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
}

.topbar h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: #333;
}

/* ---------- Menu / navigation ---------- */
.menu {
  display: flex;
  gap: 4px;
  background: #fff;
  padding: 0 24px;
  border-bottom: 1px solid #e2e5ea;
  overflow-x: auto;
}

.menu-btn {
  border: none;
  background: transparent;
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 700;
  color: #6a6f77;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.menu-btn:hover {
  color: var(--blue-dark);
}

.menu-btn.active {
  color: var(--blue-dark);
  border-bottom-color: var(--blue);
}

.view {
  animation: fade 0.15s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.container {
  max-width: 900px;
  margin: 28px auto;
  padding: 0 16px;
}

.search-panel {
  background: #fff;
  border-radius: 10px;
  padding: 22px 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  margin-bottom: 28px;
}

.search-panel label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  color: #444;
}

.search-row {
  display: flex;
  gap: 10px;
}

.search-row input {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid #c8ccd2;
  border-radius: 8px;
  outline: none;
}

.search-row input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.2);
}

.search-row button {
  padding: 12px 26px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.search-row button:hover {
  background: #143d7d;
}

.hint {
  margin: 12px 0 0;
  font-size: 13px;
  color: #7a7a7a;
}

.status {
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 600;
  min-height: 18px;
}

.status.error {
  color: #c0392b;
}

.status.ok {
  color: #1e8449;
}

.card-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card-toolbar {
  width: 100%;
  max-width: 194mm;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.card-toolbar button {
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.card-toolbar button:hover {
  background: #143d7d;
}

/* ---------- Shared button variants ---------- */
.btn-secondary {
  background: #eef1f5 !important;
  color: var(--blue-dark) !important;
  border: 1px solid #cfd5dd !important;
}

.btn-secondary:hover {
  background: #e2e7ee !important;
}

.btn-danger {
  background: #c0392b !important;
  color: #fff !important;
}

.btn-danger:hover {
  background: #a5301f !important;
}

/* ---------- Forms (Agregar / Editar) ---------- */
.panel-title {
  margin: 0 0 18px;
  font-size: 18px;
  color: #333;
}

.form-panel,
.list-panel {
  background: #fff;
  border-radius: 10px;
  padding: 22px 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.orden-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.form-field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #6a6f77;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #c8ccd2;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.2);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.form-actions button {
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.form-actions button:hover {
  background: #143d7d;
}

/* ---------- Agregar Cliente (inline) ---------- */
.add-inline {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.add-inline input {
  flex: 1;
  min-width: 240px;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.add-inline input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.2);
}

.add-inline button {
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.add-inline button:hover {
  background: #143d7d;
}

/* ---------- Listado / tabla ---------- */
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.list-head .panel-title {
  margin: 0;
}

#listFilter {
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid #c8ccd2;
  border-radius: 8px;
  outline: none;
  min-width: 200px;
}

#listFilter:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.2);
}

.table-wrap {
  overflow-x: auto;
}

.orden-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.orden-table th,
.orden-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #e6e9ee;
}

.orden-table th {
  background: #f6f8fa;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #6a6f77;
}

.orden-table tbody tr:hover {
  background: #f9fbfd;
}

.orden-table .c-orden {
  font-weight: 800;
  color: var(--blue-dark);
}

.col-actions {
  text-align: right;
  white-space: nowrap;
}

.row-btn {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.row-btn:hover {
  background: #143d7d;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 40, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 760px;
  padding: 22px 24px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: #9aa0a8;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: #444;
}

.orden-card {
  position: relative;
  width: 100%;
  max-width: 194mm;
  background: #fff;
  border: 2px solid #b8b8b8;
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.orden-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--brand-watermark, url("logo.png"));
  background-repeat: no-repeat;
  background-position: center;
  background-size: 70%;
  opacity: 0.07;
  pointer-events: none;
  z-index: 0;
}

.orden-head,
.orden-fields {
  position: relative;
  z-index: 1;
}

.orden-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 22px;
}

.orden-label {
  background: var(--blue-dark);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.5px;
  padding: 14px 16px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.orden-number {
  background: var(--blue);
  color: #062a4f;
  font-weight: 800;
  font-size: 30px;
  text-align: center;
  padding: 10px 16px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orden-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-row {
  display: grid;
  grid-template-columns: 260px 1fr;
  align-items: stretch;
  gap: 16px;
}

.field-key {
  background: var(--gray-label);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3px;
  padding: 9px 12px;
  border-radius: 3px;
  display: flex;
  align-items: center;
}

.field-val {
  font-size: 14px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-bottom: 1px solid var(--gray-line);
}

/* ---------- Cabecera de listas con acciones ---------- */
.head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.head-actions input {
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid #c8ccd2;
  border-radius: 8px;
  outline: none;
  min-width: 180px;
}

.head-actions input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.2);
}

.head-actions button {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.head-actions button:hover {
  background: #143d7d;
}

/* ---------- Campos de solo lectura ---------- */
.form-field input.readonly {
  background: #f1f3f6;
  color: #666;
  cursor: not-allowed;
}

/* ---------- Botones de acción por fila (múltiples) ---------- */
.col-actions .row-btn + .row-btn {
  margin-left: 6px;
}

/* ---------- Validación: badges y resumen ---------- */
.val-summary {
  display: flex;
  gap: 10px;
  margin: 4px 0 16px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge-ok {
  background: #e3f6ea;
  color: #1e8449;
  border: 1px solid #bfe6cd;
}

.badge-err {
  background: #fdecea;
  color: #c0392b;
  border: 1px solid #f4c7c0;
}

/* ---------- Importar Factura ---------- */
.import-config {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px 20px;
  margin: 8px 0 4px;
}

.key-row {
  display: flex;
  gap: 8px;
}

.key-row input {
  flex: 1;
}

.key-row button {
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}

.import-upload {
  margin: 16px 0 4px;
  border: 2px dashed #b9c2ce;
  border-radius: 12px;
  background: #f8fafc;
  padding: 26px 20px;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.import-upload.dragover {
  border-color: var(--blue);
  background: #eef8fd;
}

.upload-inner p {
  margin: 6px 0;
  color: #55606c;
  font-size: 14px;
}

.upload-icon {
  font-size: 40px;
  line-height: 1;
}

.import-upload button {
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.form-field-wide {
  grid-column: 1 / -1;
}

.form-field textarea {
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #c8ccd2;
  border-radius: 8px;
  outline: none;
  resize: vertical;
}

.form-field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.2);
}

#importResult {
  margin-top: 22px;
}

.doc-saveall-bar {
  margin-top: 22px;
}

.doc-saveall-bar .form-actions button {
  background: #1f8a4c;
}

.doc-saveall-bar .form-actions button:hover {
  background: #176b3a;
}

/* ---------- Vista previa de documentos ---------- */
.doc-previews {
  display: flex;
  flex-direction: column;
  gap: 26px;
  margin-top: 24px;
}

.doc-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.doc-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 194mm;
  margin-bottom: 8px;
}

.doc-preview-toolbar button {
  flex-shrink: 0;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #1a5fb4;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.doc-preview-toolbar button:hover {
  background: #164a8f;
}

.doc-preview-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.doc-preview-actions .btn-secondary {
  background: #eef1f5 !important;
  color: var(--blue-dark) !important;
  border: 1px solid #cfd5dd !important;
}

.doc-preview-actions .btn-secondary:hover {
  background: #e2e7ee !important;
}

/* Aislamiento de impresión: cuando body.printing-doc está activo, solo se
   imprime el .doc-sheet marcado como .print-target. */
@media print {
  body.printing-doc * {
    visibility: hidden;
  }
  body.printing-doc .print-target,
  body.printing-doc .print-target * {
    visibility: visible;
  }
  body.printing-doc .print-target {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: none;
    border: none;
    box-shadow: none;
  }

  /* Compactación para que la Carta de Porte / Manifiesto quepan en una sola
     página A4. Solo aplica al imprimir desde Documentos (body.printing-doc),
     sin afectar la vista previa en pantalla ni la descarga PDF (que usa
     canvasToPdf y su propio paginado). */
  body.printing-doc .doc-sheet {
    font-size: 11px;
    padding: 8px 10px;
  }
  body.printing-doc .doc-logo {
    max-width: 200px;
  }
  body.printing-doc .doc-logo-header {
    margin-bottom: 6px;
  }
  body.printing-doc .doc-head {
    margin-bottom: 8px;
  }
  body.printing-doc .doc-title {
    font-size: 13px;
    padding: 8px 10px;
  }
  body.printing-doc .doc-num {
    min-width: 100px;
    font-size: 15px;
    padding: 8px 10px;
  }
  body.printing-doc .doc-transporte,
  body.printing-doc .doc-fecha {
    padding: 4px 8px;
    margin-bottom: 6px;
  }
  body.printing-doc .doc-grid {
    margin-bottom: 6px;
  }
  body.printing-doc .doc-grid th,
  body.printing-doc .doc-grid td {
    padding: 3px 6px;
  }
  /* Las filas de la tabla de ítems ocupan menos espacio en print. */
  body.printing-doc .doc-items-carta tr,
  body.printing-doc .doc-items-manifiesto tr {
    height: 18px;
  }
  body.printing-doc .doc-items-carta td,
  body.printing-doc .doc-items-manifiesto td {
    height: 18px;
    max-height: 18px;
  }
  /* Recuadro de observaciones más compacto. */
  body.printing-doc .doc-obs {
    min-height: 36px;
    padding: 5px 8px;
    margin-bottom: 6px;
  }
  body.printing-doc .doc-obs-carta {
    min-height: 64px;
  }
  body.printing-doc .doc-obs-body {
    min-height: 36px;
  }
  /* Pie de Carta de Porte: firmas y Condiciones de Pago más compactas. */
  body.printing-doc .doc-foot-carta {
    padding-top: 6px;
  }
  body.printing-doc .doc-sign-area {
    min-height: 48px;
  }
  body.printing-doc .doc-pago {
    flex: 1;
  }
  body.printing-doc .doc-pago-table th,
  body.printing-doc .doc-pago-table td {
    padding: 3px 6px;
  }
}

.doc-preview-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #6a6f77;
}

.doc-sheet {
  position: relative;
  width: 100%;
  max-width: 194mm;
  background: #fff;
  border: 1px solid #b8b8b8;
  border-radius: 6px;
  padding: 16px 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  font-size: 12.5px;
  color: #1a1a1a;
  overflow: hidden;
  box-sizing: border-box;
}

.doc-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--brand-watermark, url("logo.png"));
  background-repeat: no-repeat;
  background-position: center;
  background-size: 65%;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
}

.doc-sheet > * {
  position: relative;
  z-index: 1;
}

.doc-logo-header {
  text-align: center;
  margin-bottom: 14px;
}

.doc-logo {
  display: inline-block;
  width: 100%;
  max-width: 300px;
  height: auto;
  object-fit: contain;
}

.doc-head {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 12px;
}

.doc-title {
  flex: 1;
  background: var(--blue-dark);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  padding: 12px 14px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.doc-num {
  min-width: 130px;
  background: var(--blue);
  color: #062a4f;
  font-weight: 800;
  font-size: 18px;
  padding: 10px 14px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.doc-transporte {
  margin-bottom: 10px;
  padding: 6px 10px;
  background: #f2f4f7;
  border-radius: 4px;
}

.doc-topline {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 10px;
}

.doc-topline .doc-transporte {
  flex: 1;
  margin-bottom: 0;
}

.doc-fecha {
  min-width: 200px;
  padding: 6px 10px;
  background: #f2f4f7;
  border-radius: 4px;
  text-align: right;
}

.doc-grid {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  table-layout: fixed;
}

.doc-grid th,
.doc-grid td {
  border: 1px solid #cfd5dd;
  padding: 6px 9px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.doc-grid th {
  background: #eef2f6;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #55606c;
}

.doc-parties td {
  width: 50%;
}

.doc-conductor td {
  width: 50%;
}

.doc-items td {
  font-size: 12px;
}

/* Las celdas de ítems muestran el valor completo: el texto largo se ajusta en
   varias líneas en vez de recortarse. La altura crece con el contenido. */
.doc-items-carta th,
.doc-items-carta td,
.doc-items-manifiesto th,
.doc-items-manifiesto td {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  vertical-align: top;
}

.doc-items-manifiesto .doc-empty-row td,
.doc-items-carta .doc-empty-row td {
  height: 26px;
}

/* Filas en blanco editables directamente en la vista previa (inputs) */
.doc-cell-edit {
  padding: 0 !important;
}

.doc-cell-input {
  width: 100%;
  height: 100%;
  min-height: 24px;
  box-sizing: border-box;
  border: 0;
  margin: 0;
  padding: 4px 8px;
  background: #fffef5;
  font: inherit;
  font-size: 12px;
  color: #1a1a1a;
  outline: none;
  border-radius: 0;
}

.doc-cell-input:hover {
  background: #fff9db;
}

.doc-cell-input:focus {
  background: #fffbe6;
  box-shadow: inset 0 0 0 2px #f5c518;
}

/* Celdas de texto editables: crecen con el contenido y ajustan el texto en
   varias líneas para mostrar el valor completo (sin recorte). */
.doc-cell-textarea {
  height: auto;
  resize: none;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.3;
  display: block;
}

/* Number inputs en celdas: ocultar spinners para que no rompan el layout compacto */
.doc-cell-input[type="number"]::-webkit-outer-spin-button,
.doc-cell-input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.doc-cell-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* En impresión / PDF: input sin fondo ni recuadro, se ve como texto normal */
@media print {
  .doc-cell-input {
    background: transparent !important;
    box-shadow: none !important;
  }
}

/* Captura para PDF (html2canvas): mismo efecto que impresión. */
.doc-sheet.pdf-capturing .doc-cell-input {
  background: transparent !important;
  box-shadow: none !important;
}

.doc-total td {
  background: #f6f8fa;
  font-weight: 700;
}

.doc-total .doc-total-input {
  background: #fffbe6;
  font-weight: 700;
}

.doc-obs {
  border: 1px solid #cfd5dd;
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 10px;
  min-height: 60px;
  line-height: 1.5;
}

.doc-obs-title {
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.3px;
  color: #55606c;
  margin-bottom: 4px;
}

.doc-obs-carta {
  display: flex;
  gap: 14px;
  align-items: stretch;
  min-height: 110px;
}

.doc-obs-carta .doc-obs-left {
  flex: 1.4;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e6e9ee;
  padding-right: 14px;
}

.doc-obs-carta .doc-obs-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.doc-obs-carta .doc-obs-body {
  flex: 1;
  min-height: 70px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.doc-foot {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  padding-top: 6px;
  border-top: 1px solid #e6e9ee;
}

.doc-foot-carta {
  flex-direction: row;
  align-items: stretch;
  gap: 12px;
  border-top: none;
  padding-top: 8px;
}

.doc-signatures {
  flex: 0 0 25%;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.doc-sign-box {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.doc-sign-area {
  flex: 1;
  min-height: 78px;
  border: 1px solid #b8b8b8;
  background: #fff;
}

.doc-sign-label {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
}

.doc-pago {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.doc-pago-title {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  padding: 4px 0;
  border: 1px solid #b8b8b8;
  border-bottom: none;
  background: #f5f7fa;
}

.doc-pago-table {
  table-layout: fixed;
  width: 100%;
  font-size: 12px;
}

.doc-pago-table th,
.doc-pago-table td {
  padding: 5px 8px;
  text-align: center;
}

.doc-pago-table th {
  background: #f5f7fa;
}

.doc-pago-table .num {
  text-align: center;
  white-space: nowrap;
}

.doc-pago-table .label {
  text-align: left;
  font-weight: 600;
}

.doc-pago-table .doc-total td {
  font-weight: 700;
  border-top: 1px solid #4a4a4a;
}

@media (max-width: 620px) {
  .doc-foot-carta {
    flex-direction: column;
  }
  .doc-signatures {
    flex-direction: column;
  }
}

/* Toggle Costa Rica / Exportación en Importar Factura */
.doc-tipo-toggle {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 18px;
  padding: 14px 16px;
  border: 1px solid #e6e9ee;
  border-radius: 10px;
  background: #fafbfc;
}

.doc-tipo-label {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.seg-control {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid #c9ced6;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.seg-control .seg {
  position: relative;
  margin: 0;
  cursor: pointer;
}

.seg-control .seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-control .seg span {
  display: block;
  padding: 8px 20px;
  font-size: 13.5px;
  font-weight: 600;
  color: #4a5568;
  user-select: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.seg-control .seg + .seg span {
  border-left: 1px solid #c9ced6;
}

.seg-control .seg input:checked + span {
  background: #1f6feb;
  color: #fff;
}

.seg-control .seg input:focus-visible + span {
  outline: 2px solid #1f6feb;
  outline-offset: -2px;
}

.doc-tipo-hint {
  margin: 0;
}

.footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: #8a8a8a;
}

/* ---------- Sidebar: Guía rápida ---------- */
.guide-sidebar {
  position: fixed;
  top: 130px;
  right: 24px;
  width: 280px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e2e5ea;
  border-left: 3px solid var(--blue);
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  padding: 16px 18px;
  font-size: 13px;
  color: #444;
  z-index: 50;
}

.guide-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eef0f3;
}

.guide-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.guide-head-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.guide-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #8a9099;
}

.guide-subtitle {
  font-size: 15px;
  font-weight: 700;
  color: var(--blue-dark);
  line-height: 1.2;
}

.guide-body p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.guide-body p:last-child,
.guide-body ul:last-child {
  margin-bottom: 0;
}

.guide-body ul {
  margin: 0 0 10px;
  padding-left: 18px;
}

.guide-body li {
  margin-bottom: 5px;
  line-height: 1.45;
}

.guide-body li:last-child {
  margin-bottom: 0;
}

.guide-body strong {
  color: var(--blue-dark);
}

.guide-body code {
  background: #eef2f6;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  color: #1a4fa0;
}

.guide-section + .guide-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #e6e9ee;
}

.guide-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #6a6f77;
  margin: 0 0 6px;
}

@media (max-width: 1280px) {
  .guide-sidebar {
    display: none;
  }
}

@media print {
  body {
    background: #fff;
  }
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .topbar,
  .menu,
  .search-panel,
  .footer,
  .no-print {
    display: none !important;
  }
  .container {
    margin: 0;
    padding: 0;
    max-width: none;
  }
  .card-wrapper {
    display: block;
  }
  .orden-card {
    max-width: none;
    box-shadow: none;
    border: 2px solid #b8b8b8;
  }
  @page {
    margin: 12mm;
  }
}

@media (max-width: 620px) {
  .orden-form {
    grid-template-columns: 1fr;
  }
  .import-config {
    grid-template-columns: 1fr;
  }
  .doc-sheet {
    font-size: 11px;
    padding: 14px;
  }
  .orden-head {
    grid-template-columns: 1fr;
  }
  .field-row {
    grid-template-columns: 150px 1fr;
    gap: 8px;
  }
  .field-key {
    font-size: 11px;
  }
  .field-val {
    justify-content: flex-start;
    text-align: left;
  }
}

/* ===========================================================================
   Login screen + user menu
   =========================================================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a4fa0 0%, #29aae1 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  padding: 36px 32px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.login-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.login-logo {
  height: 56px;
  width: auto;
  object-fit: contain;
}

.login-title {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--blue-dark);
  font-weight: 700;
}

.login-subtitle {
  margin: 0 0 22px;
  font-size: 14px;
  color: #5a6473;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.login-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: #5a6473;
  text-transform: uppercase;
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--gray-line);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 170, 225, 0.18);
}

.login-form button {
  margin-top: 8px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--blue-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.login-form button:hover {
  background: #143d80;
}

.login-status {
  margin: 14px 0 0;
  font-size: 13px;
  color: #5a6473;
  min-height: 18px;
}

.login-status.error {
  color: #c0392b;
}

.login-devlink {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--blue-dark);
  word-break: break-all;
}

.login-devlink a {
  color: var(--blue-dark);
  font-weight: 600;
}

/* User menu in the topbar */
.topbar-spacer {
  flex: 1 1 auto;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-email {
  font-size: 13px;
  color: #5a6473;
  font-weight: 600;
}

.btn-logout {
  padding: 6px 14px;
  font-size: 13px;
}

/* ===========================================================================
   Manifiesto Master — tabla de ítems editable y hoja del documento
   =========================================================================== */

.master-items-table {
  table-layout: fixed;
}

.master-items-table th,
.master-items-table td {
  vertical-align: top;
}

.master-items-table .master-item-cell {
  padding: 0;
}

.master-items-table .master-item-cell input {
  width: 100%;
  box-sizing: border-box;
  border: 0;
  margin: 0;
  padding: 6px 8px;
  background: #fffef5;
  font: inherit;
  font-size: 12.5px;
  color: #1a1a1a;
  outline: none;
}

.master-items-table .master-item-cell input:focus {
  background: #fffbe6;
  box-shadow: inset 0 0 0 2px #f5c518;
}

.master-items-table tfoot td {
  background: #f6f8fa;
  font-weight: 700;
}

/* Hoja del documento Manifiesto Master (vista previa + PDF) */
.doc-master-headline {
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #1a1a1a;
  padding: 4px 0 8px;
  border-bottom: 1px solid #e6e9ee;
  margin-bottom: 10px;
}

.doc-master-row {
  display: flex;
  gap: 14px;
  margin-bottom: 6px;
  font-size: 12.5px;
}

.doc-master-row > div {
  flex: 1;
}

.doc-master-row > div b {
  color: #062a4f;
}

.doc-master-code-row {
  margin-top: 8px;
  padding: 6px 10px;
  background: #f2f4f7;
  border-radius: 4px;
}

.doc-master-code-row > div:first-child {
  flex: 1.4;
  font-size: 14px;
  font-weight: 700;
}

.doc-items-master th,
.doc-items-master td {
  font-size: 12px;
}

.doc-items-master .doc-empty-row td {
  height: 26px;
}

.doc-master-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #e6e9ee;
  font-size: 13px;
  font-weight: 700;
  color: #062a4f;
}

/* En impresión / PDF: la hoja del Manifiesto Master se ve como las demás. */
body.printing-doc .doc-master-headline,
body.printing-doc .doc-master-row,
body.printing-doc .doc-master-code-row,
body.printing-doc .doc-master-foot {
  display: flex;
}



/* ===========================================================================
   Cotización — hoja del documento (vista previa + PDF + impresión)
   =========================================================================== */
.cot-consecutivo {
  font-size: 14px;
  color: #6a6f77;
}

.cot-consecutivo strong {
  color: var(--blue-dark);
}

.orden-table tr.row-active td {
  background: #eef6fb;
}

/* La cotización no lleva la marca de agua de los demás documentos. */
.doc-sheet:has(.cot-doc)::after {
  display: none;
}

.cot-doc {
  font-size: 12.5px;
  color: #1a1a1a;
  padding: 4px 18px 12px;
}

.cot-doc .doc-logo-header {
  margin-bottom: 4px;
}

.cot-title {
  max-width: 420px;
  margin: 0 auto 22px;
  text-align: center;
  font-size: 19px;
  line-height: 1.25;
}

.cot-meta {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px 12px;
  margin-bottom: 22px;
}

.cot-meta-label {
  font-size: 12.5px;
}

.cot-meta-split {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-right: 60px;
}

.cot-section {
  margin: 16px 0 8px;
  font-size: 13px;
  letter-spacing: 0.2px;
}

.cot-detail {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
}

.cot-detail th {
  background: var(--blue-dark);
  color: #fff;
  font-weight: 400;
  text-align: left;
  padding: 7px 8px;
  border: 1px solid var(--blue-dark);
}

.cot-detail th:first-child,
.cot-detail td:first-child {
  width: 37%;
}

.cot-detail td {
  padding: 6px 8px;
  border: 1px solid #c8ccd2;
}

.cot-list {
  margin: 0 0 6px;
  padding-left: 16px;
  font-size: 11.5px;
  line-height: 1.6;
}

.cot-notes {
  margin-top: 16px;
  font-size: 11.5px;
  font-style: italic;
  color: #333;
}

.cot-notes p {
  margin: 0 0 3px;
}

.cot-closing {
  margin: 18px 0 36px;
  line-height: 1.5;
}

.cot-sign {
  margin-left: 62%;
  line-height: 1.8;
  font-size: 12.5px;
}

.doc-sheet.pdf-capturing:has(.cot-doc) {
  border: none;
}

body.printing-doc .cot-doc {
  font-size: 12px;
}

body.printing-doc .doc-sheet:has(.cot-doc) {
  border: none;
}

/* visibility:hidden conserva el alto de la app y agrega páginas en blanco al
   imprimir; aquí la hoja impresa es hija directa del body, así que lo demás
   puede salir del flujo. */
@media print {
  body.printing-doc:has(> .print-target .cot-doc) > :not(.print-target) {
    display: none !important;
  }
}

/* ============ White label / modo demo ============ */
.brand-wordmark {
  display: inline-block;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--blue-dark);
  text-transform: uppercase;
  line-height: 1.1;
}

.brand-logo-wordmark {
  font-size: 22px;
  white-space: nowrap;
}

.login-logo-wordmark {
  font-size: 26px;
}

.doc-logo-wordmark {
  font-size: 28px;
  padding: 6px 0;
  border-bottom: 3px solid var(--blue);
}

.demo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--blue-dark);
}

.demo-banner-warning {
  background: #b45309;
}

.demo-banner .demo-reset-btn {
  padding: 4px 12px;
  font-size: 12px;
}

.demo-login-hint {
  margin: 0 0 16px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--blue-dark);
  background: #eef6fb;
  border: 1px dashed var(--blue);
  border-radius: 8px;
}

.demo-samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 4px;
  font-size: 14px;
  color: #55606c;
}

.demo-samples p {
  flex-basis: 100%;
  margin: 0;
  text-align: center;
}

.demo-samples button {
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
}

.is-demo #changePasswordBtn {
  display: none;
}
