:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #e5732a;      /* naranja del encabezado del shipping list */
  --accent-dark: #c65f1d;
  --accent-soft: #fdeee3;
  --ok: #1e8e4a;
  --ok-soft: #e3f5ea;
  --warn: #c98a00;
  --warn-soft: #fff4d6;
  --bad: #c62828;
  --bad-soft: #fde8e8;
  --info: #2563eb;
  --info-soft: #e5edff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--info); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.2px; }
.cargando { text-align: center; padding: 60px 0; color: var(--muted); }
.error { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; font-size: 14px; }

/* ---------- Barra superior ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand-sm { color: var(--accent-dark); font-weight: 700; font-size: 16px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.brand-sm .logo { color: initial; }
.brand-sm .nombre-corto { display: none; }
.menu-btn { display: none; }
#topbar .menu { display: contents; }
#topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#topbar nav a {
  color: var(--text); padding: 8px 12px; border-radius: 8px; font-weight: 500; font-size: 14px;
}
#topbar nav a.active { background: var(--accent-soft); color: var(--accent-dark); }
#topbar nav a:hover { background: var(--bg); }
.user-menu { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.user-chip { color: var(--text); font-size: 14px; padding: 6px 10px; border-radius: 8px; background: var(--bg); }
.user-chip small { color: var(--muted); text-transform: uppercase; font-size: 10.5px; margin-left: 4px; letter-spacing: 0.4px; }

.aviso-seguridad {
  background: var(--warn-soft); color: #8a5d00; font-size: 13.5px; text-align: center; padding: 6px 12px;
  border-top: 1px solid #f0d48a;
}
.aviso-seguridad a { color: #8a5d00; font-weight: 700; text-decoration: underline; }

/* ---------- Compartir app ---------- */
.compartir { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.compartir .qr { text-align: center; }
.compartir .qr svg { width: 100%; max-width: 280px; height: auto; display: block; margin: 0 auto 8px; }
.compartir .url { font-size: 15px; font-weight: 600; word-break: break-all; }
@media (max-width: 760px) { .compartir { grid-template-columns: 1fr; } }

/* ---------- Botón flotante (siguiente partida sin foto) ---------- */
.btn-flotante {
  position: fixed; right: 16px; bottom: 20px; z-index: 30;
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 10px 18px;
  border-radius: 999px; border: none; background: var(--text); color: #fff; font: inherit; font-weight: 700;
  font-size: 15px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.btn-flotante .badge { background: var(--accent); border-radius: 999px; padding: 2px 9px; font-size: 13px; }
.btn-flotante:active { transform: translateY(1px); }

/* ---------- Contenedor ---------- */
#app { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.count { background: var(--bg); color: var(--muted); font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back { display: inline-block; font-size: 13.5px; margin-bottom: 4px; }

/* ---------- Cabecera del detalle de CC (plegable en celular) ---------- */
.cc-head { display: block; }
.cc-titulo { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.cc-titulo .back { font-size: 20px; margin: 0; line-height: 1; text-decoration: none; }
.cc-titulo h2 { margin: 0; }
.avance-mini { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--muted); background: var(--bg); padding: 3px 10px; border-radius: 999px; }
.cc-head .progress { margin-bottom: 10px; }
/* En escritorio los bloques plegables se muestran siempre abiertos y sin su título */
.plegable > summary { display: none; }
.plegable > *:not(summary) { display: block; }
.plegable.acciones-cc { margin-top: 10px; }
.plegable .meta { margin-bottom: 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); font-size: 14px; }
.meta b { color: var(--text); font-weight: 600; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap; transition: background 0.12s, transform 0.05s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #f1c4c4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { background: #17733b; }
.btn.bad { background: var(--surface); color: var(--bad); border-color: #f1c4c4; }
.btn.bad:hover { background: var(--bad-soft); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.cam { background: var(--info); border-color: var(--info); color: #fff; min-height: 44px; }
.btn.cam:hover { background: #1d4fd8; }
.btn.icon { padding: 4px 8px; min-height: 32px; font-size: 14px; }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
label > input, label > select, label > textarea, .input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; font-weight: 400; background: var(--surface); color: var(--text);
  min-height: 40px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { margin: 0; flex: 1 1 160px; }
.inline-form .btn { flex: 0 0 auto; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ---------- Login ---------- */
.login { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.brand { text-align: center; margin-bottom: 20px; }
.brand .logo { font-size: 44px; display: block; }
.brand h1 { font-size: 22px; margin: 6px 0 2px; }
.brand p { color: var(--muted); font-size: 14px; }

/* ---------- Chips y estados ---------- */
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  vertical-align: middle; white-space: nowrap;
}
/* El estado del CC viene en minúsculas de la base */
.chip.abierto, .chip.cerrado { text-transform: capitalize; }
.chip.pendiente { background: #eceff3; color: #4b5563; }
.chip.revision { background: var(--warn-soft); color: #8a5d00; }
.chip.aprobado, .chip.cerrado { background: var(--ok-soft); color: var(--ok); }
.chip.rechazado { background: var(--bad-soft); color: var(--bad); }
.chip.abierto { background: var(--info-soft); color: var(--info); }
.mini { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: #eceff3; color: #4b5563; margin-right: 6px; }
.mini.ok { background: var(--ok-soft); color: var(--ok); }
.mini.warn { background: var(--warn-soft); color: #8a5d00; }
.mini.bad { background: var(--bad-soft); color: var(--bad); }
.comentario { margin-top: 4px; font-size: 13px; color: var(--bad); background: var(--bad-soft); padding: 4px 8px; border-radius: 6px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); color: var(--text); display: block; border-left: 5px solid var(--info);
}
.kpi .n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi.ok { border-left-color: var(--ok); }
.kpi.warn { border-left-color: var(--warn); }
.kpi.bad { border-left-color: var(--bad); }
.kpi.neutral { border-left-color: #9aa3ae; }

/* ---------- Progreso ---------- */
.progress { display: flex; height: 12px; border-radius: 999px; background: #e7eaee; overflow: hidden; }
.progress span { display: block; height: 100%; }
.p-aprobado { background: var(--ok); }
.p-revision { background: #f2b233; }
.p-rechazado { background: var(--bad); }
.avance .leyenda { margin-top: 8px; }

/* ---------- Tabs y filtros ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.tabs a, .tabs button {
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.tabs .active { background: var(--text); color: #fff; border-color: var(--text); }
.tabs .buscar { margin-left: auto; flex: 1 1 200px; max-width: 320px; }

/* ---------- Tablas ---------- */
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th {
  text-align: left; background: var(--accent); color: #fff; padding: 9px 10px; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 700;
}
.tabla th:first-child { border-radius: 8px 0 0 0; }
.tabla th:last-child { border-radius: 0 8px 0 0; }
.tabla td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tabla tr.clickable { cursor: pointer; }
.tabla tr.clickable:hover td { background: #fafbfc; }
.tabla .cant { text-align: center; font-weight: 700; font-size: 16px; }
.tabla .acciones { white-space: nowrap; }
.tabla .acciones .btn { margin-right: 4px; }
.tabla .progress { min-width: 120px; }
.vacio { color: var(--muted); padding: 16px; text-align: center; }

.thumb {
  width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; cursor: zoom-in; display: block;
}
.thumb.ref { object-fit: contain; }
.thumb.lg, .noimg.lg { width: 200px; height: 150px; }
.noimg { display: inline-flex; align-items: center; justify-content: center; width: 84px; height: 84px; border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); font-size: 12px; text-align: center; }
.fotos-grid { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.col-btns { display: flex; flex-direction: column; gap: 6px; }
.foto { position: relative; margin: 0; }
.foto .x {
  position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff;
  background: var(--bad); color: #fff; font-size: 16px; line-height: 24px; cursor: pointer; padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.verificar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Fichas de partida (detalle de CC): la imagen es el protagonista ---------- */
.fichas { padding-bottom: 16px; } /* el espacio del botón flotante lo deja .embarque, que va después */
.ficha {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 16px;
  box-shadow: var(--shadow); overflow: hidden;
}
.ficha-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: #fafbfc;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.ficha-head .num {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px;
}
.ficha-titulo { flex: 1 1 200px; display: flex; flex-direction: column; min-width: 0; }
.item-code { font-size: 17px; }
.desc { color: var(--muted); font-size: 14px; }
.cant-badge { font-size: 13px; color: var(--muted); background: var(--bg); padding: 4px 12px; border-radius: 8px; white-space: nowrap; }
.cant-badge b { font-size: 20px; color: var(--text); margin-left: 4px; }
.ficha-cuerpo { display: grid; grid-template-columns: 1fr 1fr; }
.panel { padding: 12px 14px; min-width: 0; }
.panel.ref { border-right: 1px solid var(--border); }
.panel-titulo { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.img-grande {
  display: block; width: 100%; height: 340px; object-fit: contain; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; cursor: zoom-in;
}
.sin-imagen {
  height: 180px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border);
  border-radius: 8px; color: var(--muted); background: #fafbfc;
}
.sin-imagen.chica { height: 120px; margin-bottom: 10px; }
.fotos-grande { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 12px; }
.fotos-grande.una { grid-template-columns: 1fr; }
.img-foto {
  display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); cursor: zoom-in; background: #eef0f3;
}
.fotos-grande.una .img-foto { height: 300px; aspect-ratio: auto; object-fit: contain; }
.foto-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.ficha-pie {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px;
  border-top: 1px solid var(--border); flex-wrap: wrap; background: #fafbfc;
}
.ficha-pie .comentario { display: inline-block; }
.ficha.estado-aprobado { border-color: #a9dcb9; }
.ficha.estado-aprobado .ficha-head { background: var(--ok-soft); }
.ficha.estado-rechazado { border-color: #efb3b3; }
.ficha.estado-rechazado .ficha-head { background: var(--bad-soft); }
.ficha.estado-revision { border-color: #f0d48a; }
.ficha.estado-revision .ficha-head { background: var(--warn-soft); }

/* ---------- Apartado de embarque (la pieza ya cargada; no sale en el PDF) ---------- */
.embarque {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 72px; /* espacio para el botón flotante */
}
.embarque-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 10px;
}
.embarque-head h3 { margin: 0; font-size: 17px; }
.embarque-head p { margin: 2px 0 0; }
.embarque-head .cuenta {
  display: inline-block; background: var(--info); color: #fff; border-radius: 999px;
  padding: 1px 9px; font-size: 13px; vertical-align: middle;
}
/* Chip de la cabecera que baja a la sección de embarque */
.chip-ir {
  border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer;
  padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.chip-ir:hover { background: var(--surface); border-color: var(--info); color: var(--info); }

/* Tarjetas en pantallas chicas */
@media (max-width: 760px) {
  #app { padding: 12px; }

  /* --- Barra superior: una sola fila con menú desplegable --- */
  .topbar-inner { padding: 6px 12px; gap: 8px; }
  .brand-sm { font-size: 15px; }
  .brand-sm .nombre-corto { display: inline; }
  .brand-sm .nombre-largo { display: none; }
  .menu-btn {
    display: block; margin-left: auto; width: 42px; height: 42px; flex: 0 0 auto;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
    font-size: 20px; line-height: 1; cursor: pointer; color: var(--text);
  }
  #topbar .menu { display: none; }
  #topbar.menu-abierto .menu {
    display: block; width: 100%; order: 3; border-top: 1px solid var(--border);
    margin: 6px -12px -6px; padding: 8px 12px; background: var(--bg);
  }
  #topbar.menu-abierto .topbar-inner { flex-wrap: wrap; }
  #topbar nav { flex-direction: column; gap: 2px; }
  #topbar nav a { padding: 12px; font-size: 15px; }
  .user-menu { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--border); }
  .user-chip { flex: 1; }

  /* --- Cabecera del CC: datos y acciones plegados, lado a lado --- */
  .cc-head { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
  .cc-titulo, .cc-head > .progress { grid-column: 1 / -1; }
  .cc-titulo h2 { font-size: 19px; }
  .plegable[open] { grid-column: 1 / -1; }  /* al abrirse ocupa el ancho completo */
  .plegable {
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-top: 0;
  }
  .plegable.acciones-cc { margin-top: 0; }
  .plegable > summary {
    display: block; padding: 10px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
    list-style: none; color: var(--text);
  }
  .plegable > summary::after { content: ' ▾'; color: var(--muted); }
  .plegable[open] > summary::after { content: ' ▴'; }
  .plegable > summary::-webkit-details-marker { display: none; }
  .plegable > *:not(summary) { padding: 0 12px 12px; }
  .plegable .actions { flex-direction: column; }
  .plegable .actions .btn { width: 100%; }
  .tabla thead { display: none; }
  .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
  .tabla tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; padding: 6px 0; background: var(--surface); }
  .tabla td { border: none; padding: 6px 12px; display: flex; gap: 10px; align-items: flex-start; }
  .tabla td::before {
    content: attr(data-label); flex: 0 0 105px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px;
    color: var(--muted); font-weight: 700; padding-top: 3px;
  }
  .tabla td[data-label=""]::before, .tabla td:not([data-label])::before { display: none; }
  .tabla .cant { text-align: left; }
  .thumb, .noimg { width: 110px; height: 110px; }
  .thumb.lg, .noimg.lg { width: 100%; max-width: 320px; height: 200px; }
  .btn.cam { width: 100%; min-height: 52px; font-size: 16px; }
  .fotos-grid { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }

  /* Fichas: paneles apilados, imagen a todo el ancho (el tamaño de la imagen no se toca) */
  .ficha-cuerpo { grid-template-columns: 1fr; }
  .panel.ref { border-right: none; border-bottom: 1px solid var(--border); }
  .img-grande { height: 280px; }
  .sin-imagen { height: 120px; }
  .fotos-grande { grid-template-columns: 1fr 1fr; }
  .fotos-grande.una .img-foto { height: 260px; }
  .embarque { padding: 12px; margin-bottom: 76px; }
  .embarque-head { flex-direction: column; align-items: stretch; }
  /* En celular los botones de la fila se separan y crecen: el de eliminar no debe
     quedar tan pegado al de PDF que se toque por error. */
  .tabla .acciones { display: flex; gap: 12px; }
  .tabla .acciones .btn { margin-right: 0; min-height: 40px; }
  .tabla .acciones > a.btn { flex: 1; }
  .tabla .acciones > button.btn { padding: 4px 18px; }
  .ficha-pie { flex-direction: column; align-items: stretch; }
  .verificar .btn { flex: 1; }

  /* Menos aire alrededor de las imágenes: la partida cabe en menos scroll */
  .ficha { margin-bottom: 12px; }
  .ficha-head { gap: 6px 10px; padding: 8px 12px; }
  .ficha-head .num { width: 28px; height: 28px; font-size: 13px; }
  .ficha-titulo { flex: 1 1 140px; }
  .ficha-head .cant-badge, .ficha-head .chip { margin-left: 38px; } /* alineados bajo el texto */
  .item-code { font-size: 16px; }
  .panel { padding: 10px 12px; }
  .panel-titulo { margin-bottom: 6px; }
  .fotos-grande { gap: 8px; margin-bottom: 10px; }
  .foto-meta { font-size: 11px; }
}

/* ---------- Toast, lightbox, modal ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25); max-width: 92vw;
}
#toast.bad { background: var(--bad); }
#toast.ok { background: var(--ok); }

#lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.88);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
#lightbox .cerrar {
  position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.15); color: #fff; font-size: 28px; cursor: pointer;
}

.modal-bg { position: fixed; inset: 0; z-index: 40; background: rgba(16,24,40,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 520px; margin: 0; max-height: 90vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- Vista de impresión (shipping list) ---------- */
.print-page { background: #fff; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); }
.print-head { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 40px; margin-bottom: 16px; }
/* El logo va a la izquierda, a la altura del título, igual que en el PDF */
.print-logo { position: absolute; top: 0; left: 0; height: 32px; width: auto; }
.print-head h1 { grid-column: 1 / -1; text-align: center; font-size: 16px; letter-spacing: 1px; margin-bottom: 8px; }
.print-head div { display: flex; gap: 8px; font-size: 13px; border-bottom: 1px solid #333; padding: 2px 0; }
.print-head b { min-width: 60px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.print-table th { background: var(--accent); color: #fff; padding: 6px; text-align: left; font-size: 11.5px; border: 1px solid #999; }
.print-table td { border: 1px solid #999; padding: 6px; vertical-align: middle; text-align: center; }
.print-table td.txt { text-align: left; }
.print-table img { max-width: 260px; max-height: 180px; object-fit: contain; margin: 2px; }
.print-table .fotos-print { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: 280px; }
.print-table .fotos-print img { object-fit: cover; width: 130px; height: 100px; }
.print-table .fotos-print img:only-child { width: 240px; height: 180px; object-fit: contain; }
.print-firmas { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 40px; margin-top: 40px; font-size: 12px; text-align: center; }
.print-firmas div { border-top: 1px solid #333; padding-top: 4px; }
.no-print { margin-bottom: 12px; display: flex; gap: 8px; }

@media print {
  #topbar, .no-print, #toast { display: none !important; }
  body { background: #fff; }
  #app { max-width: none; padding: 0; }
  .print-page { border: none; padding: 0; border-radius: 0; }
  .print-table tr { page-break-inside: avoid; }
  /* El encabezado naranja se repite arriba de cada hoja impresa */
  .print-table thead { display: table-header-group; }
  .print-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-logo { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
