/* =========================================
   TRAZABILIDAD · DIAGRAMA IOS
========================================= */

.produccion-trace-diagram-wrap {
  max-height: 68vh;
  overflow: auto;
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: color-mix(in srgb, var(--lj-surface) 72%, transparent);
  touch-action: pan-x pan-y;
}

.produccion-trace-diagram {
  min-width: 100%;
  padding: 14px;
  transform-origin: top left;
}

.produccion-trace-toolbar-zoom {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 6px;
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: color-mix(in srgb, var(--lj-surface) 88%, transparent);
  backdrop-filter: none;
}

.produccion-trace-toolbar-zoom .inventario-threshold-btn {
  flex: 0 0 auto;
}

.produccion-trace-zoom-value {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 58px;
  text-align: center;
  font-weight: 800;
  color: var(--lj-accent);
  background: var(--lj-accent-soft);
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  padding: 4px 8px;
  min-height: 36px;
}

.produccion-trace-ingredient-card {
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
  padding: 8px;
}

.produccion-trace-ingredient-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.produccion-trace-ingredient-head-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.produccion-trace-ingredient-index {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  flex: 0 0 24px;
  border-radius: 50%;
  background: var(--lj-accent-soft);
  color: var(--lj-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.75rem;
}

.produccion-trace-ingredient-head-main h6 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.produccion-trace-ingredients {
  gap: 14px;
  padding-right: 4px;
}

.produccion-trace-ingredient-card {
  background: var(--lj-surface);
  padding: 8px;
}

.produccion-trace-lot-card {
  background: var(--lj-surface);
  border-color: var(--lj-border);
  padding: 8px;
}

.produccion-trace-ingredient-card .inventario-threshold-btn {
  flex-shrink: 0;
}

.produccion-trace-ingredient-card .inventario-threshold-btn span {
  white-space: nowrap;
}

.produccion-trace-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.produccion-trace-card-actions .inventario-no-photo-btn,
.produccion-trace-card-actions .inventario-threshold-btn {
  margin: 0;
}

.produccion-trace-used-badge {
  border: 1px solid var(--lj-border);
  border-radius: 4px;
  background: var(--lj-accent-soft);
  color: var(--lj-accent);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 8px;
}

.produccion-trace-mermaid-wrap {
  border: 2px dashed var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background-image: radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--lj-muted) 22%, transparent) 1px, transparent 0);
  background-size: 18px 18px;
  background-color: var(--lj-surface);
  margin-bottom: 14px;
  overflow: hidden;
}

.produccion-trace-mermaid {
  min-height: 260px;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.produccion-trace-mermaid-loading {
  min-height: 240px;
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  color: var(--lj-accent);
}

.produccion-trace-mermaid-loading .meta-spinner-login {
  font-size: 58px;
}

.produccion-trace-mermaid-loading p {
  margin: 0;
  font-weight: 600;
}

.produccion-trace-fallback-diagram {
  display: grid;
  gap: 10px;
  text-align: left;
}

.produccion-trace-fallback-flow {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
}

.produccion-trace-fallback-node {
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
  padding: 6px 10px;
  min-width: 150px;
  display: grid;
  gap: 2px;
  flex: 1 1 160px;
}

.produccion-trace-fallback-node small {
  color: var(--lj-accent);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.produccion-trace-fallback-node strong {
  color: var(--lj-accent);
}

.produccion-trace-fallback-node span {
  color: var(--lj-accent);
  font-size: 0.8rem;
}

.produccion-trace-fallback-arrow {
  align-self: center;
  color: var(--lj-accent);
  font-weight: 800;
  font-size: 1rem;
}

.produccion-trace-fallback-meta {
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
  padding: 6px 10px;
}

.produccion-trace-fallback-meta p {
  margin: 0;
  color: var(--lj-accent);
  font-size: 0.84rem;
}

.produccion-trace-fallback-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.produccion-trace-fallback-list li {
  color: var(--lj-accent);
  display: grid;
  gap: 2px;
}

.produccion-trace-fallback-list li span {
  color: var(--lj-accent);
  font-size: 0.82rem;
}

.produccion-trace-mermaid.is-dragging {
  cursor: grabbing;
}

.produccion-trace-mermaid .mermaid {
  min-width: 640px;
  width: max-content;
  font-size: 14px;
}

.produccion-trace-mermaid svg {
  max-width: none;
  height: auto;
  display: block;
}

@media (max-width: 991.98px) {
  .toolbar-scroll-x,
  .produccion-toolbar-actions,
  .inventario-toolbar-actions {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    flex-wrap: nowrap;
  }

  .toolbar-scroll-x::-webkit-scrollbar,
  .produccion-toolbar-actions::-webkit-scrollbar,
  .inventario-toolbar-actions::-webkit-scrollbar {
    height: 5px;
  }

  .toolbar-scroll-x::-webkit-scrollbar-thumb,
  .produccion-toolbar-actions::-webkit-scrollbar-thumb,
  .inventario-toolbar-actions::-webkit-scrollbar-thumb {
    background: var(--lj-accent-soft);
    border-radius: 4px;
  }

  .dispatch-actions-row {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .dispatch-actions-row .recipe-table-action-btn,
  .dispatch-actions-row sl-button {
    width: 100%;
    max-width: none;
    justify-content: center;
  }

  .dispatch-vehicle-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .dispatch-vehicle-actions sl-button {
    width: 100%;
    max-width: none;
    justify-content: center;
  }

  .dispatch-client-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .swal2-popup.produccion-umbral-alert .swal2-html-container {
    padding-inline: 0;
  }

  .swal2-popup.produccion-umbral-alert .inventario-collapse-head-styled {
    flex-direction: row;
    align-items: center;
  }

  .swal2-popup.produccion-umbral-alert .produccion-config-actions sl-button {
    width: 100%;
    max-width: none;
    justify-content: center;
  }

  .produccion-rne-file-row {
    grid-template-columns: 1fr;
  }

  .produccion-trace-fallback-arrow {
    width: 100%;
    text-align: center;
  }

  .produccion-trace-diagram {
    padding: 10px;
  }

  .produccion-trace-toolbar-zoom {
    width: fit-content;
    max-width: 100%;
    margin-inline: auto;
    justify-content: center;
    gap: 6px;
    padding: 6px;
  }

  .produccion-trace-zoom-value {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 52px;
    padding: 4px 6px;
    font-size: 0.86rem;
    min-height: 36px;
  }

  .produccion-trace-lot-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .produccion-trace-grid {
    grid-template-columns: 1fr;
  }

  .produccion-trace-ingredient-card header {
    flex-direction: column;
    align-items: stretch;
  }

  .produccion-trace-ingredient-card .inventario-threshold-btn {
    width: 100%;
    justify-content: center;
  }

  .produccion-trace-mermaid .mermaid {
    min-width: 320px;
  }
}

.produccion-rne-spinner{font-size: 24px;}

.receta-rnpa-inline{display: flex;align-items: center;gap: 8px;flex-wrap: wrap;margin: 4px 0;}
.receta-rnpa-badge{display: inline-flex;align-items: center;gap: 6px;border-radius: 4px;padding: 4px 10px;font-size: .72rem;font-weight: 700;border: 1px solid var(--lj-border);background: var(--lj-accent-soft);color: var(--lj-accent);}
.receta-rnpa-badge.is-pending,.receta-rnpa-badge.is-danger{background: var(--lj-danger-soft);border-color: color-mix(in srgb, var(--lj-danger) 35%, var(--lj-surface));color: var(--lj-danger);}
.receta-rnpa-badge.is-warning{background: var(--lj-warning-soft);border-color: color-mix(in srgb, var(--lj-warning) 35%, var(--lj-surface));color: var(--lj-warning);}
.receta-rnpa-badge.is-ok{background: var(--lj-surface-2);border-color: color-mix(in srgb, var(--lj-success) 35%, var(--lj-surface));color: var(--lj-success);}
.receta-rnpa-badge.is-exempt{background: var(--lj-surface-2);border-color: var(--lj-border);color: var(--lj-accent);}
.receta-rnpa-days{font-size: .75rem;color: var(--lj-accent);display: inline-flex;align-items: center;gap: 4px;}
.receta-rnpa-days.is-warning{color: var(--lj-warning);font-weight: 700;}
.receta-rnpa-days.is-danger{color: var(--lj-danger);font-weight: 700;}
.receta-rnpa-days.is-ok{color: var(--lj-success);font-weight: 700;}
.recetas-rnpa-filters{display: flex;gap: 8px;overflow-x: auto;flex-wrap: nowrap;padding: 4px 2px 12px;scrollbar-width: thin;}
.recetas-rnpa-filters .inventario-status-btn:disabled{opacity: .45;cursor: not-allowed;}
.recipe-rnpa-block{border: 1px solid var(--lj-border);border-radius: var(--lj-radius-lg);padding: 10px;background: var(--lj-surface);}
.recipe-rnpa-exempt-row{margin: 4px 0 10px;color: var(--lj-brand);font-weight: 700;}
.recipe-rnpa-grid{display: grid;grid-template-columns: repeat(2,minmax(0,1fr));gap: 8px;}
.recipe-rnpa-grid.is-disabled{opacity: .52;filter: saturate(.75);}
.recipe-rnpa-actions{grid-column: 1 / -1;display: flex;justify-content: flex-start;}
@media (max-width:768px){.recipe-rnpa-grid{grid-template-columns: 1fr;}}

.inventario-collapse-head-styled i.bi{margin-right: 6px;color: var(--lj-accent);}
.inventario-collapse-head-styled{transition: background-color .2s ease,border-color .2s ease;}
.inventario-collapse-head-styled:hover{background: var(--lj-accent-soft);border-color: var(--lj-border);}
.inventario-collapse-head-styled.is-open{background: var(--lj-accent-soft);border-color: var(--lj-border-strong);}
.produccion-rne-expiry-alert{display: flex;align-items: center;gap: 8px;border-radius: var(--lj-radius-lg);padding: 10px 12px;margin-bottom: 10px;border: 1px solid color-mix(in srgb, var(--lj-warning) 35%, var(--lj-surface));background: var(--lj-warning-soft);color: var(--lj-warning);font-weight: 600;}
.produccion-rne-expiry-alert.is-danger{border-color: color-mix(in srgb, var(--lj-danger) 35%, var(--lj-surface));background: var(--lj-danger-soft);color: var(--lj-danger);}
.produccion-rne-expiry-alert.is-ok{border-color: color-mix(in srgb, var(--lj-success) 35%, var(--lj-surface));background: var(--lj-surface-2);color: var(--lj-success);}
.produccion-rne-expiry-alert i{font-size: 1rem;}
.produccion-rne-expiry-alert.is-collapsible {
  width: 100%;
  cursor: pointer;
  justify-content: space-between;
  text-align: left;
}

.produccion-rne-expiry-text,
.produccion-rne-expiry-collapse-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.produccion-rne-expiry-collapse-meta strong {
  min-width: 24px;
  text-align: center;
}

.produccion-rne-expiry-collapse-meta i {
  transition: transform 0.2s ease;
}

.produccion-rne-expiry-alert.is-collapsible.is-open .produccion-rne-expiry-collapse-meta i {
  transform: rotate(180deg);
}

.produccion-expiry-alert-card,
.inventario-expiry-alert-host {
  margin-bottom: 10px;
}

/* Card que envuelve el alert colapsable + los detalles. Antes tenía borde y
   fondo propios, lo que generaba un "div dentro de div" visualmente. Ahora
   actúa como simple contenedor transparente; el botón interno (.produccion-
   rne-expiry-alert) es el único elemento con look de pill. Sólo cuando está
   EXPANDIDO mostramos el fondo del card para enmarcar los detalles. */
.produccion-expiry-alert-card {
  border: none;
  background: transparent;
  padding: 0;
}

.produccion-expiry-alert-card.is-expanded {
  border: 1px solid color-mix(in srgb, var(--lj-warning) 35%, var(--lj-surface));
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
  padding: 8px;
}

.produccion-expiry-alert-card.is-danger.is-expanded {
  border-color: color-mix(in srgb, var(--lj-danger) 35%, var(--lj-surface));
  background: var(--lj-surface);
}

/* Cuando el card está expandido, el botón interno queda pegado al borde top.
   Sacamos su margin-bottom para que no haga doble espacio. */
.produccion-expiry-alert-card.is-expanded .produccion-rne-expiry-alert {
  margin-bottom: 8px;
}

.produccion-expiry-alert-details {
  display: grid;
  gap: 8px;
}

.produccion-expiry-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.produccion-expiry-list {
  display: grid;
  gap: 6px;
}

.produccion-expiry-row {
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
  padding: 7px;
  display: grid;
  grid-template-columns: auto 34px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.produccion-expiry-select {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}

.produccion-expiry-row.is-expired {
  border-color: color-mix(in srgb, var(--lj-danger) 35%, var(--lj-surface));
  background: var(--lj-surface);
}

.produccion-expiry-row.is-soon {
  border-color: color-mix(in srgb, var(--lj-warning) 35%, var(--lj-surface));
  background: var(--lj-surface);
}

.produccion-expiry-thumb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--lj-border);
  background: var(--lj-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--lj-accent);
}

.produccion-expiry-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.produccion-expiry-info {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.produccion-expiry-info strong {
  color: var(--lj-brand);
  font-size: 0.9rem;
  line-height: 1.1;
}

.produccion-expiry-info small {
  color: var(--lj-accent);
  font-weight: 700;
}

.produccion-expiry-qty {
  color: var(--lj-success);
  font-weight: 900;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .produccion-expiry-row {
    grid-template-columns: auto 34px minmax(0, 1fr);
  }

  .produccion-expiry-row .inventario-threshold-btn,
  .produccion-expiry-qty {
    grid-column: 2 / -1;
    justify-self: start;
  }
}

.produccion-modal-rne-badges{display: inline-flex;align-items: center;gap: 8px;flex-wrap: wrap;margin-left: 8px;}
.produccion-modal-rne-badge{display: inline-flex;align-items: center;gap: 6px;border: 1px solid var(--lj-border);background: var(--lj-accent-soft);color: var(--lj-accent);border-radius: 4px;padding: 3px 10px;font-size: .72rem;font-weight: 700;}
.produccion-modal-rne-badge.is-warning{background: var(--lj-warning-soft);border-color: color-mix(in srgb, var(--lj-warning) 35%, var(--lj-surface));color: var(--lj-warning);}
.produccion-modal-rne-badge.is-danger{background: var(--lj-danger-soft);border-color: color-mix(in srgb, var(--lj-danger) 35%, var(--lj-surface));color: var(--lj-danger);}
.produccion-modal-rne-badge.is-ok{background: var(--lj-surface-2);border-color: color-mix(in srgb, var(--lj-success) 35%, var(--lj-surface));color: var(--lj-success);}


/* =========================================
   TRAZABILIDAD · LAYOUT LIMPIO + VISOR DEL DIAGRAMA (JS/ui/trace-diagram.js)
   Sin recuadros anidados ni scroll interno: la ventana / página scrollea una sola vez.
========================================= */
.produccion-trace-apple-viewer {
  border: 0;
  padding: 0;
  background: none;
}
.produccion-trace-diagram-wrap {
  max-height: none;
  overflow: visible;
  border: 0;
  background: none;
  touch-action: auto;
}
.produccion-trace-diagram {
  padding: 0;
  display: grid;
  gap: 14px;
  min-width: 0;
}
.produccion-trace-mermaid-wrap {
  border: 0;
  background: none;
  margin: 0;
  overflow: visible;
  min-width: 0;
}
.produccion-trace-mermaid-wrap > .produccion-trace-mermaid-loading {
  min-height: 220px;
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
}
.produccion-trace-mermaid-wrap > .produccion-trace-mermaid-loading .meta-spinner-login { font-size: 34px; }

.lj-trace-dia {
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius-lg);
  background: var(--lj-surface);
  box-shadow: var(--lj-shadow-sm, 0 1px 2px rgba(15, 23, 42, .06));
  overflow: hidden;
  min-width: 0;
}
.lj-trace-dia-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--lj-border);
  background: var(--lj-surface-2);
}
.lj-trace-dia-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--lj-muted);
  min-width: 0;
}
.lj-trace-dia-title i { color: var(--lj-accent); }
.lj-trace-dia-title-short { display: none; }
.lj-trace-dia-tools {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.lj-trace-dia-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--lj-border);
  border-radius: var(--lj-radius);
  background: var(--lj-surface);
  color: var(--lj-text);
  font-size: 13px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.lj-trace-dia-btn:hover { background: var(--lj-accent-soft); border-color: var(--lj-border-strong); color: var(--lj-accent); }
.lj-trace-dia-btn:focus-visible { outline: 2px solid var(--lj-accent); outline-offset: 1px; }
.lj-trace-dia-zoom {
  min-width: 48px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--lj-muted);
}
.lj-trace-dia-viewport {
  position: relative;
  height: 420px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  /* Un dedo en vertical sigue scrolleando la página; horizontal y pellizco mueven el diagrama. */
  touch-action: pan-y;
  /* El diagrama siempre sobre "papel" claro (sus colores están pensados para fondo claro). */
  background-color: #f8fafc;
  background-image: radial-gradient(circle at 1px 1px, rgba(100, 116, 139, .18) 1px, transparent 0);
  background-size: 20px 20px;
}
.lj-trace-dia-viewport.is-dragging { cursor: grabbing; }
.lj-trace-dia-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.lj-trace-dia-canvas svg { display: block; max-width: none; }
/* Las etiquetas se miden al generar el diagrama: no cambiar su interlineado acá. Si una fuente tarda en cargar,
   que el texto no quede recortado por su caja. */
.lj-trace-dia-canvas svg foreignObject { overflow: visible; }
.lj-trace-dia-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .72);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .25s ease;
}
.lj-trace-dia-hint.is-hidden { opacity: 0; }

/* Pantalla completa: API del navegador o, si no hay (iPhone), fijo sobre todo. */
.lj-trace-dia.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 100000;
  border-radius: 0;
  border: 0;
  display: flex;
  flex-direction: column;
}
.lj-trace-dia.is-fullscreen .lj-trace-dia-viewport { flex: 1 1 auto; height: auto !important; touch-action: none; }
.lj-trace-dia:fullscreen { background: var(--lj-surface); }
html.lj-trace-dia-open, html.lj-trace-dia-open body { overflow: hidden; }

@media (max-width: 768px) {
  .lj-trace-dia-head { padding: 6px 6px 6px 10px; }
  .lj-trace-dia-title { font-size: 11px; }
  .lj-trace-dia-title-long { display: none; }
  .lj-trace-dia-title-short { display: inline; }
  .lj-trace-dia-btn { width: 34px; height: 34px; }
  .lj-trace-dia-zoom { min-width: 40px; }
}
@media (max-width: 380px) {
  .lj-trace-dia-zoom { display: none; }
}
/* Las etiquetas del diagrama se miden en <body> y se muestran dentro de ventanas con otro interlineado: se fija
   el mismo en ambos lugares (el id del SVG empieza con lj_trace_ al medir y al mostrar). */
svg[id^="lj_trace_"] foreignObject div,
svg[id^="lj_trace_"] foreignObject span,
svg[id^="lj_trace_"] foreignObject p { line-height: 1.5; font-size: 15px; letter-spacing: normal; }
