:root {
  --ink: #1c1917;
  --muted: #6b6459;
  --line: #e4ded3;
  --paper: #f3f0e8;
  --surface: #fffdf8;
  --forest: #163d2b;
  --forest-2: #1f5139;
  --leaf: #2d6a4f;
  --mint: #e7f3ec;
  --gold: #c4923a;
  --gold-soft: #f8eed8;
  --danger: #9b2c2c;
  --danger-soft: #fdecec;
  --info: #1d4e89;
  --info-soft: #e8f0fa;
  --shadow: 0 4px 14px rgba(22, 61, 43, 0.06);
  --radius: 10px;
  --touch: 40px;
  --sidebar: 236px;
  --sidebar-rail: 68px;
  --banner-h: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }

#ambiente-prueba {
  background: #b45309;
  color: #fff;
  text-align: center;
  padding: 6px 12px;
  font-weight: 650;
  font-size: 12px;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  z-index: 80;
}
#ambiente-prueba[hidden] { display: none !important; }
body:has(#ambiente-prueba:not([hidden])) { --banner-h: 32px; }

html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
p { margin: 0; }

.app, .login { min-height: 100%; min-height: 100vh; }

/* ===== Login ===== */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
}
.login-brand {
  background:
    radial-gradient(800px 420px at 20% 0%, rgba(196,146,58,.28), transparent 50%),
    linear-gradient(180deg, #1a4a33 0%, var(--forest) 100%);
  color: #f6f3eb;
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.mark {
  display: flex; align-items: center; gap: 12px;
}
.mark-badge {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--gold);
  color: var(--forest);
  display: grid; place-items: center;
  font-weight: 800; font-size: 22px;
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
}
.mark small { display: block; opacity: .75; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.mark strong { font-size: 18px; letter-spacing: .04em; }
.login-brand h1 { font-size: 28px; line-height: 1.15; margin: 18px 0 8px; }
.login-brand p { color: rgba(246,243,235,.82); font-size: 16px; max-width: 32ch; }
.proto-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.18);
  color: #f8eed8;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  width: fit-content;
}
.login-panel { padding: 24px 28px; overflow: auto; }
.demo-note {
  background: var(--gold-soft);
  border: 1px solid #ead6a8;
  color: #6a4b12;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 24px;
  font-size: 14px;
}
.demo-note strong { color: #4c350b; }
.role-grid { display: grid; gap: 14px; }
.role-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex; align-items: center; gap: 16px;
  text-align: left;
  min-height: 92px;
  width: 100%;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.role-card:hover, .role-card:focus-visible {
  border-color: var(--leaf);
  transform: translateY(-1px);
  outline: none;
}
.avatar {
  width: 56px; height: 56px; border-radius: 16px;
  display: grid; place-items: center;
  font-weight: 700; color: #fff; flex-shrink: 0;
  letter-spacing: .02em;
}
.role-card h3 { font-size: 18px; }
.role-card .role { color: var(--leaf); font-weight: 650; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.role-card .hint { color: var(--muted); font-size: 14px; margin-top: 2px; }
.enter {
  margin-left: auto;
  background: var(--forest);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 44px;
  font-weight: 650;
  pointer-events: none;
}
.login-foot { margin-top: 22px; color: var(--muted); font-size: 13px; }

/* ===== Shell ===== */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: calc(100vh - var(--banner-h)); }
.sidebar {
  background: var(--forest);
  color: #f6f3eb;
  padding: 12px 10px 10px;
  display: flex; flex-direction: column; gap: 10px;
  position: sticky; top: var(--banner-h); height: calc(100vh - var(--banner-h));
  z-index: 45;
  overflow-y: auto;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button {
  background: transparent; border: 0; color: inherit;
  min-height: 36px;
  border-radius: 8px;
  padding: 0 10px;
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; text-align: left;
  font-size: 13px;
  width: 100%;
}
.nav button[aria-current="page"], .nav button.active {
  background: rgba(255,255,255,.14);
}
.nav button:hover { background: rgba(255,255,255,.08); }
.side-user {
  background: rgba(255,255,255,.08);
  border-radius: 10px;
  padding: 8px;
  display: flex; align-items: center; gap: 8px;
}
.side-user .meta { font-size: 11px; opacity: .75; }
.side-actions { margin-top: auto; display: grid; gap: 8px; }
.btn {
  border: 0; border-radius: 8px;
  min-height: var(--touch);
  padding: 0 12px;
  font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px;
}
.btn-gold { background: var(--gold); color: #1c1406; }
.btn-ghost { background: rgba(255,255,255,.1); color: #fff; }
.btn-primary { background: var(--forest); color: #fff; }
.btn-secondary { background: #fff; color: var(--forest); border: 1px solid var(--line); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn[disabled] { opacity: .6; cursor: default; }

.main { padding: 14px 16px 20px; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.eyebrow { color: var(--leaf); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.topbar h1 { font-size: 20px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.banner {
  background: var(--info-soft);
  border: 1px solid #c9daf0;
  color: #16365e;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: 12px;
}
.banner strong { color: #102844; }
.banner code { font-size: 12px; background: #fff; padding: 1px 6px; border-radius: 6px; }
.banner details { margin-top: 6px; }
.banner summary { cursor: pointer; font-weight: 650; color: var(--info); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}
.stat .lbl { color: var(--muted); font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.stat .val { font-size: 18px; font-weight: 700; margin-top: 2px; }

.filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 8px;
  margin-bottom: 14px;
}
.filters .field-search { grid-column: 1 / -1; }
.field, .field-box { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 13px; font-weight: 650; color: #44403a; }
input, select, textarea {
  min-height: var(--touch);
  border: 1px solid #d7d0c3;
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  width: 100%;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(45,106,79,.28);
  outline-offset: 1px;
}
.list { display: grid; gap: 10px; }
.lot, .lot-fila { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0; box-shadow: var(--shadow); overflow: hidden; width: 100%; }
.lot-lista { display: flex; flex-direction: column; gap: 8px; }
.lot-resumen { display: grid; grid-template-columns: minmax(7.5rem, 1.1fr) minmax(5rem, 0.7fr) minmax(6rem, 1fr) auto 5.6rem 4.2rem minmax(7rem, 1fr) auto;
  gap: 6px 10px; align-items: center; padding: 6px 10px; cursor: pointer; list-style: none; font-size: 12px; line-height: 1.25; }
.lot-resumen::-webkit-details-marker, .lot-resumen::marker { display: none; }
.lot-resumen:hover, .lot-fila[open] .lot-resumen { background: var(--mint); }
.lot-code { font-weight: 700; font-size: 14px; color: var(--forest); }
.lot-oc, .lot-date { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lot-prod { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lot-lb, .lot-rend { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.lot-alertas { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.lot-costo { font-size: 11px; min-width: 0; }
.lot-costo .costo { margin: 0; }
.lot-detalle { padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.lot-alertas-lista { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.lot h3 { font-size: 17px; }
.lot .sub { color: var(--muted); font-size: 14px; margin-top: 3px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  background: var(--mint);
  color: var(--forest);
}
.st-en_proceso { background: var(--gold-soft); color: #6a4b12; }
.st-completado { background: var(--mint); color: var(--forest); }
.st-en_revision { background: var(--info-soft); color: var(--info); }
.st-anulado { background: #f3f3f3; color: #57534e; }

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed #d7d0c3;
  border-radius: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.span-2 { grid-column: 1 / -1; }
.readonly {
  background: #f6f3ec;
  color: #44403a;
}
.po-btn {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid #d7d0c3;
  border-radius: 12px;
  min-height: 72px;
  padding: 10px 12px;
}
.po-btn .muted { color: var(--muted); font-size: 13px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.detail {
  display: grid;
  grid-template-columns: 1.3fr .7fr;
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 10px 12px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; }
.items { margin-top: 12px; padding: 0; list-style: none; display: grid; gap: 8px; }
.items li {
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; justify-content: space-between; gap: 8px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.user-row { display: flex; align-items: center; gap: 10px; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(28, 25, 23, .45);
  display: grid; place-items: center;
  padding: 24px;
  z-index: 40;
}
.modal {
  background: var(--surface);
  width: min(760px, 100%);
  max-height: min(80vh, 800px);
  overflow: auto;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.po-option {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.po-option:hover { border-color: var(--leaf); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-head h2 { font-size: 22px; }
.ejemplo {
  display: inline-block;
  background: var(--gold-soft);
  color: #6a4b12;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

.toast {
  position: fixed;
  right: 20px; bottom: 24px;
  background: var(--forest);
  color: #fff;
  padding: 14px 16px;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  z-index: 50;
  max-width: 360px;
}

.bottom-nav { display: none !important; }

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { min-height: auto; padding: 20px 18px; }
  .login-panel { padding: 20px 16px 32px; }
  .form-grid, .filters { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .field-search { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat { padding: 8px 6px; }
  .stat .val { font-size: 16px; }
  .lot-resumen { grid-template-columns: 1fr auto; gap: 3px 8px; padding: 8px 10px; }
  .lot-code { grid-column: 1; }
  .lot-resumen > .chip { grid-column: 2; justify-self: end; }
  .lot-prod { grid-column: 1 / -1; white-space: normal; }
  .lot-oc, .lot-lb, .lot-rend, .lot-costo { grid-column: 1; text-align: left; }
  .lot-alertas { grid-column: 1 / -1; justify-content: flex-start; }
  .chips { justify-content: flex-start; }
  .detail { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .topbar h1 { font-size: 18px; }
}

/* ===== Añadidos v0 funcional ===== */
.login-panel form { display: grid; gap: 14px; max-width: 420px; }
.error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c7c7; border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.ok-msg { background: var(--mint); color: var(--forest); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.oc-card, .oc-fila { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0; box-shadow: var(--shadow); }
.oc-lista { display: flex; flex-direction: column; gap: 8px; }
.oc-fila { overflow: hidden; }
.oc-resumen { display: grid; grid-template-columns: minmax(7.5rem, 1.1fr) 6.5rem minmax(8rem, 1.4fr) auto minmax(8rem, 1.5fr); gap: 8px 12px; align-items: center;
  padding: 8px 12px; cursor: pointer; list-style: none; font-size: 13px; line-height: 1.25; }
.oc-resumen::-webkit-details-marker, .oc-resumen::marker { display: none; }
.oc-resumen:hover, .oc-fila[open] .oc-resumen { background: var(--mint); }
.oc-num { font-weight: 700; font-size: 14px; color: var(--forest); }
.oc-fecha { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.oc-prov { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oc-sum { color: #44403a; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.oc-detalle { padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.oc-ayuda-estado { margin: 6px 0 10px; }
.oc-card h3 { font-size: 17px; }
.oc-lines { margin: 6px 0 0; padding: 0; list-style: none; font-size: 14px; color: #44403a; }
@media (max-width: 900px), (orientation: portrait) {
  .oc-resumen { grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 12px; }
  .oc-num { grid-column: 1; }
  .oc-resumen .chip { grid-column: 2; justify-self: end; }
  .oc-fecha { grid-column: 1; }
  .oc-prov { grid-column: 1 / -1; white-space: normal; }
  .oc-sum { grid-column: 1 / -1; text-align: left; white-space: normal; }
}
.badge-alerta { background: var(--danger-soft); color: var(--danger); }
.st-terminado { background: var(--mint); color: var(--forest); }
.st-abierta { background: var(--mint); color: var(--forest); }
.st-cerrada, .st-anulada { background: #f3f3f3; color: #57534e; }
.pct { font-variant-numeric: tabular-nums; font-weight: 700; }
.pipeline { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 6px 0 16px; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); }
.step.hecho { border-color: #b9d6c5; background: #f6fbf8; }
.step.actual { border: 2px solid var(--gold); }
.step .n { font-size: 12px; font-weight: 700; color: var(--leaf); text-transform: uppercase; letter-spacing: .06em; }
.step .w { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.step .s { font-size: 13px; color: var(--muted); }
.step .r { margin-top: 6px; font-size: 14px; }
.alerta-box { background: var(--danger-soft); border: 1px solid #f3c7c7; color: var(--danger); border-radius: 14px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.alerta-box ul { margin: 4px 0 0; padding-left: 18px; }
.big-total { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; }
.big-total .v { font-size: 34px; font-weight: 750; color: var(--forest); font-variant-numeric: tabular-nums; }
.inline { display: grid; grid-template-columns: 1fr 120px; gap: 8px; }
.pres-row { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; width: 100%; min-width: 0; }
.table-wrap > table { min-width: 36rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.section-title { font-size: 18px; margin: 18px 0 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint-conv { font-size: 13px; color: var(--leaf); font-weight: 650; min-height: 18px; }
@media (max-width: 900px), (orientation: portrait) {
  .pipeline { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .big-total .v { font-size: 28px; }
}
.filters.filters-3 { grid-template-columns: 1fr 200px auto; }
.filters.filters-fechas { grid-template-columns: 1fr 1fr auto; }
.mobile-top { display: none; }
@media (max-width: 900px) {
  .filters.filters-3 { grid-template-columns: 1fr 1fr; }
  .filters.filters-3 > .field:first-child { grid-column: 1 / -1; }
  .filters.filters-fechas > .field:first-child { grid-column: auto; }
  .filters.filters-fechas > .field:last-child { grid-column: 1 / -1; }
  .mobile-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
  .mobile-top .mt-name { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; font-size: 14px; }
  .mobile-top .btn { min-height: 40px; }
}
.sidebar { align-self: start; }
.precio { color: #8a5a12; font-weight: 650; font-size: 13px; }
.precio-total { margin-top: 8px; color: #6a4b12; background: var(--gold-soft); border-radius: 10px; padding: 6px 10px; font-size: 14px; display: inline-block; }
.filters.filters-4 { grid-template-columns: 1fr 1fr 200px auto; }
.filters.filters-5 { grid-template-columns: minmax(8rem, 0.9fr) 1fr 1fr 160px auto; }
.paginacion { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.paginacion .muted { margin-right: auto; }
.precio-total { display: block; }
@media (max-width: 900px), (orientation: portrait) {
  .filters.filters-4 { grid-template-columns: 1fr 1fr; }
  .filters.filters-5 { grid-template-columns: 1fr 1fr; }
}
/* Cuadre recibido vs. OC */
.chip.cuadre-pendiente { background: var(--gold-soft); color: #6a4b12; }
.chip.cuadre-completa { background: #e3f4e8; color: #1d6b3a; }
.chip.cuadre-excedente { background: var(--danger-soft); color: var(--danger); }
.chip.cuadre-sin_comparar { background: #eef0f2; color: #555; }
.alerta-oc { margin-top: 8px; }
.btn-mini { min-height: 30px; padding: 0 8px; font-size: 12px; }
.items li.cuadre-linea { display: block; }
.items li.cuadre-linea .chip { margin-left: 4px; }
/* Mapping: flujo de documentos compacto (estilo SAP), móvil primero */
.oc-detalle .form-actions { flex-wrap: wrap; justify-content: flex-start; }
.overlay:has(.modal-mapping), #modal-mapping .overlay {
  padding: 0;
  place-items: end stretch;
}
.modal-mapping {
  width: 100%;
  max-width: 100%;
  max-height: min(92vh, 920px);
  border-radius: 16px 16px 0 0;
  padding: 10px 10px calc(12px + var(--safe-bottom));
}
.modal-mapping .modal-head { margin-bottom: 6px; align-items: center; }
.modal-mapping .modal-head h2 { font-size: 16px; }
.modal-mapping .modal-head .muted { font-size: 12px; }
.map-flujo-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.map-flujo {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.25;
}
.map-flujo th, .map-flujo td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid #eee9df;
  white-space: nowrap;
  vertical-align: middle;
}
.map-flujo th {
  font-size: 10px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f6f3ec;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 2;
}
.map-flujo tbody tr:last-child td { border-bottom: 0; }
.map-flujo .map-doc {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  min-width: 11rem;
  max-width: 16rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.map-flujo thead .map-doc { z-index: 3; background: #f6f3ec; }
.map-flujo .num, .map-flujo .map-peso, .map-flujo .map-rend { text-align: right; font-variant-numeric: tabular-nums; }
.map-n0 .map-doc { font-weight: 700; color: var(--forest); }
.map-n1 .map-doc { padding-left: 1.15rem; }
.map-n2 .map-doc { padding-left: 2.05rem; }
.map-n3 .map-doc { padding-left: 2.95rem; }
.map-ico {
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 6px;
  border: 1px solid var(--leaf);
  background: var(--mint);
  vertical-align: middle;
  flex-shrink: 0;
}
.map-ico-lin { background: #fff; }
.map-ico-lote { background: var(--gold-soft); border-color: var(--gold); }
.map-ico-paso { background: #fff; border-color: #a8a29a; }
.map-pendiente { color: var(--muted); }
.map-pendiente .map-doc { background: #faf8f3; }
.map-pendiente .map-ico-paso { background: transparent; border-style: dashed; }
.map-pendiente .map-est { font-style: italic; font-weight: 400; }
.map-marca {
  display: inline-block;
  margin-left: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .03em;
  vertical-align: middle;
}
.map-omitidas td {
  background: #f3f3f3;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}
.map-omitidas .map-doc { background: #f3f3f3; }
.map-omitidas summary { cursor: pointer; font-weight: 650; }
.map-omitidas-det { margin-top: 4px; padding-left: 2px; }
@media (min-width: 900px) {
  .overlay:has(.modal-mapping), #modal-mapping .overlay {
    padding: 24px;
    place-items: center;
  }
  .modal-mapping {
    width: min(820px, 100%);
    max-height: min(86vh, 800px);
    border-radius: 16px;
    padding: 14px 16px 16px;
  }
}
.card-inactivo { opacity: 0.78; }

/* Tablas y tarjetas más densas */
.card { border-radius: 10px; }
table { font-size: 12px; border-collapse: collapse; width: 100%; }
th, td { padding: 5px 8px; }
.section-title { font-size: 15px; margin: 12px 0 8px; }
.pipeline { gap: 8px; margin: 4px 0 12px; }
.step { border-radius: 10px; padding: 8px 10px; }
.step .w { font-size: 16px; }
.big-total .v { font-size: 26px; }
.toast { padding: 10px 12px; border-radius: 10px; font-size: 13px; }

/* Costo unitario (solo admin) */
.costo { margin-top: 2px; font-size: 12px; }
.costo-val { font-variant-numeric: tabular-nums; color: #6a4b12; }
.costo-aviso { color: #6a4b12; font-weight: 650; background: var(--gold-soft); border-radius: 6px; padding: 2px 6px; display: inline-block; }
.costo-box { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.card .costo-box { border-top: 0; padding-top: 0; margin-top: 0; }

/* ===== Navegación tipo Alegra ===== */
.app-top { display: none; }
.nav-overlay { display: none; }
.nav-toggle {
  width: 40px; height: 40px; padding: 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; display: flex; flex-direction: column;
  justify-content: center; gap: 5px; flex-shrink: 0;
}
.nav-toggle span { display: block; height: 2px; background: var(--forest); border-radius: 1px; }
.nav-mod-btn { font-weight: 750; letter-spacing: .02em; text-transform: uppercase; font-size: 11px !important; color: #d7efe3; }
.nav-mod-btn::after {
  content: '';
  margin-left: auto;
  border: 4px solid transparent;
  border-top-color: rgba(255,255,255,.5);
}
.nav-mod.abierto .nav-mod-btn::after {
  border-top-color: transparent;
  border-bottom-color: rgba(255,255,255,.5);
  margin-bottom: 4px;
}
.nav-sub { display: none; padding: 0 0 4px 0; }
.nav-mod.abierto .nav-sub { display: block; }
.nav-item { padding-left: 14px !important; }
.nav-ico {
  width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08);
  position: relative;
}
.ico-produccion { background: #2d6a4f; }
.ico-configuracion { background: #c4923a; }
.ico-ordenes, .ico-lotes, .ico-reporte, .ico-dashboard, .ico-usuarios, .ico-parametros { background: transparent; }
.mark { display: flex; align-items: center; gap: 8px; }
.mark-badge { width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }

/* Tablet: menú en riel de iconos, expandible */
@media (max-width: 1099px) {
  .app-top {
    display: flex; align-items: center; gap: 8px;
    margin: -4px 0 10px; min-height: 40px;
  }
  .app-top-brand { display: flex; flex-direction: column; line-height: 1.1; flex: 1; min-width: 0; }
  .app-top-brand small { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
  .app-top-brand strong { font-size: 14px; color: var(--forest); }
  .app-top .mt-name { display: flex; flex-direction: column; line-height: 1.15; font-size: 12px; text-align: right; }
  .shell { grid-template-columns: var(--sidebar-rail) 1fr; }
  .sidebar { width: var(--sidebar-rail); padding: 10px 6px; overflow: hidden; }
  .sidebar .nav-txt, .sidebar .side-user > div, .sidebar .side-user .meta, .sidebar .mark > div, .sidebar .side-actions { display: none; }
  .sidebar .mark, .sidebar .side-user { justify-content: center; padding: 6px; }
  .nav-mod-btn::after { display: none; }
  .nav-item { padding-left: 8px !important; justify-content: center; }
  .nav-mod-btn { justify-content: center; padding: 0 6px; }
  .nav-overlay {
    display: block; position: fixed; inset: var(--banner-h) 0 0 0;
    background: rgba(16, 24, 20, .4); z-index: 40;
  }
  .nav-overlay[hidden] { display: none !important; }
  .shell.nav-abierta .sidebar,
  body.nav-abierta .sidebar {
    position: fixed; left: 0; top: var(--banner-h);
    width: min(var(--sidebar), 86vw);
    height: calc(100vh - var(--banner-h));
    padding: 12px 10px; overflow-y: auto; z-index: 50;
  }
  .shell.nav-abierta .sidebar .nav-txt,
  .shell.nav-abierta .sidebar .side-user > div,
  .shell.nav-abierta .sidebar .side-user .meta,
  .shell.nav-abierta .sidebar .mark > div { display: block; }
  .shell.nav-abierta .nav-mod-btn::after { display: block; }
  .shell.nav-abierta .sidebar .side-user { display: flex; justify-content: flex-start; padding: 8px; }
  .shell.nav-abierta .sidebar .mark { justify-content: flex-start; }
  .shell.nav-abierta .sidebar .side-actions { display: grid; }
  .shell.nav-abierta .nav-item { justify-content: flex-start; padding-left: 14px !important; }
  .shell.nav-abierta .nav-mod-btn { justify-content: flex-start; }
  body.nav-abierta { overflow: hidden; }
}

/* Celular: menú colapsado, drawer con overlay */
@media (max-width: 767px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: var(--banner-h);
    width: min(var(--sidebar), 88vw);
    height: calc(100vh - var(--banner-h));
    transform: translateX(-105%);
    transition: transform .2s ease;
    padding: 12px 10px; overflow-y: auto;
  }
  .sidebar .nav-txt, .sidebar .side-user > div, .sidebar .side-user .meta, .sidebar .mark > div { display: block; }
  .sidebar .side-actions { display: grid; }
  .sidebar .mark, .sidebar .side-user { justify-content: flex-start; }
  .nav-item, .nav-mod-btn { justify-content: flex-start; }
  .shell.nav-abierta .sidebar { transform: none; }
  .main { padding: 10px 12px calc(16px + var(--safe-bottom)); }
  .btn, input, select { min-height: 44px; }
  .btn-mini { min-height: 36px; }
}

@media (min-width: 1100px) {
  .app-top { display: none !important; }
  .nav-overlay { display: none !important; }
}

/* Contener el ancho de la página en celular: las tablas largas se deslizan por dentro. */
html, body, #app { max-width: 100%; }
.shell, .main, .detail, .card, .list, .lot-lista, .lot-cards, .oc-cards, .oc-tarjeta, #lotes-vista, .pipeline, .grid-2, .big-total {
  min-width: 0;
  max-width: 100%;
}
.detail, .card { overflow-x: hidden; }
.kv { grid-template-columns: minmax(0, 160px) minmax(0, 1fr); }
@media (max-width: 767px) {
  .kv { grid-template-columns: 1fr; }
  .inline, .pres-row { grid-template-columns: 1fr; }
}
.nota-moneda { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 2px; }

/* Tarjetas de lote */
.vista-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.vista-toggle button {
  border: 0; background: #fff; min-height: 36px; padding: 0 10px;
  font-weight: 650; font-size: 12px; color: var(--forest);
}
.vista-toggle button[aria-pressed="true"] { background: var(--mint); }
.lot-cards { display: grid; gap: 10px; grid-template-columns: 1fr; }
.lot-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  min-width: 0;
  max-width: 100%;
}
.lot-card:hover { border-color: #b9d6c5; }
.lot-card:focus-visible { outline: 3px solid rgba(45,106,79,.28); outline-offset: 2px; }
.lot-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; min-width: 0; }
.lot-card-tit { min-width: 0; flex: 1; }
.lot-card-code { font-weight: 750; font-size: 16px; color: var(--forest); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.lot-card-meta { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.chip.lot-card-estado {
  flex: 0 1 auto;
  white-space: normal;
  text-align: center;
  max-width: 46%;
  line-height: 1.25;
  padding: 4px 8px;
  overflow: visible;
  text-overflow: unset;
}
.st-en-empaque { background: var(--gold-soft); color: #6a4b12; }
.st-en-limpieza { background: var(--info-soft); color: var(--info); }
.st-en-desgrane { background: var(--mint); color: var(--forest-2); }
.st-en-proceso { background: #eef0f2; color: #444; }
.st-terminado { background: #e3f4e8; color: #1d6b3a; }
.st-anulado { background: var(--danger-soft); color: var(--danger); }
.lot-card-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(7rem, 11rem);
  gap: 12px;
  margin-top: 10px;
  align-items: start;
  min-width: 0;
}
.lot-card-sec { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; overflow-wrap: anywhere; }
.lot-card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lot-card-etapa { background: var(--paper); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.lot-card-etapa .lbl { display: block; font-size: 11px; color: var(--muted); }
.lot-card-etapa .val { display: block; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; overflow-wrap: anywhere; }
.lot-card-etapa.pendiente .val { color: var(--muted); font-weight: 600; font-size: 12px; }
.lot-card-lado { min-width: 0; }
.lot-card-rend { font-size: 32px; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--leaf); overflow-wrap: anywhere; }
.lot-card-rend.rend-bajo { color: var(--danger); }
.lot-card-rend.rend-alto { color: #8a5a12; }
.lot-card-rend.rend-ok { color: var(--leaf); }
.lot-card-rend.rend-sin { color: var(--muted); font-size: 22px; }
.lot-card-costo { margin-top: 10px; min-width: 0; }
.lot-card-costo-val { font-size: 20px; font-weight: 750; color: var(--ink); overflow-wrap: anywhere; }
.lot-card-costo-sub, .lot-card-costo-nota { font-size: 11px; color: var(--muted); }
.lot-card-costo-nota { margin-top: 2px; font-style: italic; overflow-wrap: anywhere; }
.lot-card-costo-aviso {
  font-size: 13px; font-weight: 650; color: #6a4b12;
  background: var(--gold-soft); border-radius: 6px; padding: 4px 6px;
  display: inline-block; overflow-wrap: anywhere; white-space: normal;
}
@media (max-width: 599px) {
  .lot-card-body, .lot-card-body.con-costo, .lot-card-body.sin-costo { grid-template-columns: 1fr; }
  .lot-card-lado { border-top: 1px dashed var(--line); padding-top: 10px; }
}
@media (min-width: 1100px) {
  .lot-cards { grid-template-columns: 1fr 1fr; }
}

/* Campos de fecha en dd/mm/aaaa (el nativo solo sirve de selector, no se ve el mm/dd del navegador). */
.fecha-ddmmaaaa, .fecha-hora-ddmmaaaa { position: relative; display: block; min-width: 0; }
.fecha-ddmmaaaa .fecha-txt, .fecha-hora-ddmmaaaa .fecha-txt { width: 100%; padding-right: 2.4rem; }
.fecha-ddmmaaaa .fecha-nativo, .fecha-hora-ddmmaaaa .fecha-nativo {
  position: absolute; right: 0; top: 0; width: 2.4rem; height: 100%;
  opacity: 0; cursor: pointer; border: 0; background: transparent;
}
.fecha-ddmmaaaa::after, .fecha-hora-ddmmaaaa::after {
  content: '';
  position: absolute; right: 10px; top: 50%; width: 12px; height: 12px;
  margin-top: -7px; border: 1.5px solid var(--leaf); border-radius: 2px;
  pointer-events: none;
}

/* Hamburguesa por encima del cajón y botón Cerrar dentro del menú (QA v8 m1). */
.nav-cerrar { display: none; }
@media (max-width: 1099px) {
  .shell.nav-abierta .nav-toggle,
  body.nav-abierta .nav-toggle {
    position: fixed;
    top: calc(var(--banner-h) + 8px);
    left: 10px;
    z-index: 60;
  }
  .shell.nav-abierta .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .shell.nav-abierta .nav-toggle span:nth-child(2) { opacity: 0; }
  .shell.nav-abierta .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
  .shell.nav-abierta .nav-toggle span { transition: transform .15s ease, opacity .15s ease; }
  .shell.nav-abierta .nav-cerrar,
  body.nav-abierta .nav-cerrar { display: block; width: 100%; }
}

/* Dashboard */
.dash-filtros { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.range-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip.dash-chip { background: #fff; border: 1px solid #d7d0c3; color: #3f3a34; cursor: pointer; }
.chip.dash-chip.on { background: var(--forest); border-color: var(--forest); color: #fff; }
.dash-filt-grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
.dash-fechas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.dash-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.dash-kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; min-width: 0; box-shadow: var(--shadow);
}
.dash-kpi .lbl { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; display: flex; align-items: center; justify-content: space-between; gap: 4px; overflow-wrap: anywhere; }
.dash-kpi .val { font-size: 22px; font-weight: 750; color: var(--forest); margin-top: 2px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; line-height: 1.15; }
.dash-kpi .hint { font-size: 11px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.dash-kpi.warn .val { color: #6a4b12; }
.dash-kpi.admin { background: linear-gradient(180deg, #fffdf8 0%, var(--gold-soft) 160%); border-color: #ead6a8; }
.dash-kpi.admin .val { color: #6a4b12; }
.tag-admin {
  background: #6a4b12; color: #f8eed8; font-size: 9px; font-weight: 700;
  letter-spacing: .03em; text-transform: uppercase; border-radius: 999px; padding: 1px 5px; white-space: nowrap;
}
.dash-charts { display: grid; grid-template-columns: 1.35fr .9fr; gap: 8px; margin-bottom: 10px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow); min-width: 0; max-width: 100%;
}
.panel-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.panel-h b { font-size: 14px; color: var(--forest); }
.dash-chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; min-width: 0; }
.dash-svg { display: block; min-width: 280px; height: 220px; }
.dash-tabla { width: 100%; }
.dash-alertas-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.dash-alertas { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.dash-alertas li {
  background: var(--paper); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; justify-content: space-between;
}
.dash-alertas a { color: var(--forest); font-weight: 700; text-decoration: none; }
.dash-alert-pct { font-weight: 750; color: var(--danger); font-variant-numeric: tabular-nums; }
.dash-badge { background: var(--danger-soft); color: var(--danger); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
@media (max-width: 1099px) {
  .dash-kpis { grid-template-columns: 1fr 1fr; }
  .dash-charts, .dash-alertas-grid { grid-template-columns: 1fr; }
  .dash-filt-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 767px) {
  .dash-kpis { grid-template-columns: 1fr; }
  .dash-filt-grid, .dash-fechas { grid-template-columns: 1fr; }
  .dash-kpi .val { font-size: 20px; }
}

/* Tarjetas compactas de órdenes de compra */
.oc-cards {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  min-width: 0;
}
.oc-tarjeta {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.oc-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; min-width: 0; }
.oc-card-tit {
  margin: 0; font-size: 13px; font-weight: 750; color: var(--forest);
  line-height: 1.3; overflow-wrap: break-word; min-width: 0; flex: 1;
}
.oc-card-tit .ejemplo { margin-left: 4px; white-space: nowrap; vertical-align: 1px; }
.oc-card-head .chip { flex: 0 0 auto; font-size: 11px; padding: 2px 7px; min-height: 0; }
.oc-card-sub { color: var(--muted); font-size: 12px; line-height: 1.3; overflow-wrap: anywhere; }
.oc-card-div { border: 0; border-top: 1px solid var(--line); margin: 4px 0 2px; }
.oc-card-cols { min-width: 0; }
.oc-card-cols-h, .oc-card-linea, .oc-card-rec {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  align-items: baseline;
}
.oc-card-cols-h { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.oc-card-cols-h span:last-child, .oc-card-cant, .oc-card-rec strong { text-align: right; }
.oc-card-linea { padding: 1px 0; }
.oc-card-prod, .oc-card-cant { min-width: 0; overflow-wrap: anywhere; font-size: 13px; line-height: 1.25; }
.oc-card-cant { font-variant-numeric: tabular-nums; justify-self: end; }
.oc-card-precio { font-size: 11px; color: #8a5a12; font-weight: 600; margin-top: 1px; }
.oc-card-corregir {
  display: inline; border: 0; background: none; padding: 0 0 0 6px;
  color: var(--leaf); font-size: 11px; font-weight: 650; cursor: pointer; text-decoration: underline;
}
.oc-card-rec { margin-top: 4px; font-size: 12px; color: var(--muted); }
.oc-card-rec strong { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 12px; }
.oc-card-bar {
  height: 6px; border-radius: 99px; background: var(--mint); overflow: hidden; margin-top: 2px;
}
.oc-card-bar-fill { display: block; height: 100%; background: var(--leaf); border-radius: 99px; }
.oc-card-bar-vacia { opacity: .45; }
.oc-card-ajuste { margin-top: 2px; }
.oc-card-ajuste .chip { font-size: 11px; padding: 2px 7px; min-height: 0; }
.oc-card-omit { font-size: 11px; }
.oc-card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 4px;
}
.oc-card-map {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 650;
}
.oc-card-map:hover { color: var(--forest); text-decoration: underline; }
.oc-card-detalle {
  margin-left: auto; color: var(--leaf); font-size: 12px; font-weight: 700;
  text-decoration: none; white-space: nowrap;
}
.oc-card-detalle:hover { text-decoration: underline; color: var(--forest); }
@media (min-width: 900px) {
  .oc-cards { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1500px) {
  .oc-cards { grid-template-columns: 1fr 1fr 1fr; }
}
