:root {
  --bg: #f3f5f8; --panel: #ffffff; --ink: #1d2433; --muted: #667085; --line: #d9dee7; --soft: #eef1f6;
  --accent: #1f5fbf; --accent-ink: #ffffff; --ok: #1d7a46; --warn: #a86400; --bad: #c0262d; --bad-soft: #fde8e8;
  --warn-soft: #fff4dd; --ok-soft: #e3f4ea; --info-soft: #e6effc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
a { color: var(--accent); }
.hidden { display: none !important; }
#app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
#topbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: #17233b; color: #fff; }
#topbar .brand { font-weight: 600; white-space: nowrap; }
#global-search { flex: 1; max-width: 560px; }
#gsearch { width: 100%; padding: 7px 10px; border-radius: 6px; border: 0; font: inherit; }
#userbox { margin-left: auto; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
#userbox button { background: transparent; color: #fff; border: 1px solid #5b6c8f; }
#sidebar { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 0; }
#sidebar a { display: flex; justify-content: space-between; padding: 7px 16px; color: var(--ink); text-decoration: none; }
#sidebar a:hover { background: var(--soft); }
#sidebar a.active { background: var(--info-soft); color: var(--accent); font-weight: 600; border-left: 3px solid var(--accent); padding-left: 13px; }
#sidebar .sec { padding: 12px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#sidebar .cnt { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
#view { overflow-y: auto; padding: 18px 22px 60px; }
h1 { font-size: 21px; margin: 0; }
h2 { font-size: 16px; margin: 18px 0 8px; }
h3 { font-size: 14px; margin: 12px 0 6px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; cursor: pointer; text-decoration: none; color: inherit; display: block; }
.card:hover { border-color: var(--accent); }
.card .t { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .v { font-size: 26px; font-weight: 600; margin: 2px 0; }
.card .v small { font-size: 13px; font-weight: 400; color: var(--muted); }
.card .s { font-size: 12px; color: var(--muted); }
.card.alert { border-left: 4px solid var(--bad); }
.card.warn { border-left: 4px solid var(--warn); }
.card.good { border-left: 4px solid var(--ok); }
button, .btn { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); border-color: #e9b4b6; }
button.small, .btn.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
input[type=checkbox] { width: 16px; height: 16px; vertical-align: middle; }
input.qty { width: 80px; text-align: right; }
textarea { width: 100%; min-height: 70px; }
label { display: inline-flex; gap: 6px; align-items: center; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.form-row .f { display: flex; flex-direction: column; gap: 3px; }
.form-row .f > span { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 8px 14px; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--soft); font-size: 12px; font-weight: 600; color: #3b4458; position: sticky; top: 0; white-space: nowrap; }
td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9fc; }
tr.prio td { background: #fff7f0; }
.neg { color: var(--bad); font-weight: 600; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: var(--soft); color: #3b4458; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--accent); }
.dep-especial, .dep-especial td { color: var(--bad) !important; font-weight: 600; }
.badge.especial { background: var(--bad); color: #fff; }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--info-soft); margin: 8px 0; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.notice.ok { background: var(--ok-soft); }
.list-compact { margin: 4px 0; padding-left: 18px; max-height: 220px; overflow-y: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; }
.kv b { color: var(--muted); font-weight: 500; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
/* órdenes en cascada: compañía → orden → repuestos */
table.cascada td.chev, table.cascada th.chev { width: 26px; padding-right: 0; text-align: center; color: var(--muted); }
table.cascada td.chev span { display: inline-block; font-size: 12px; transition: transform .15s; }
table.cascada tr.abierta > td.chev span { transform: rotate(90deg); color: var(--accent); }
table.cascada tr.ord td:nth-child(3), table.cascada tr.ord td:nth-child(4), table.cascada tr.ord td:nth-child(7) { white-space: nowrap; }
table.cascada tr.grupo td { background: #e9eef6; border-top: 2px solid #c9d3e3; font-size: 14px; }
table.cascada tr.grupo:hover td { background: #dfe7f3; }
table.cascada tr.grupo b { color: #17233b; letter-spacing: .01em; }
table.cascada tr.ord td:nth-child(2) { padding-left: 14px; }
table.cascada tr.ord.abierta td { background: var(--info-soft); }
table.cascada tr.sub > td { background: #fafbfd; padding-top: 0; }
.sub-wrap { margin: 2px 0 10px 18px; border-left: 3px solid var(--accent); padding: 6px 0 6px 12px; }
table.sub-tabla { width: 100%; font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
table.sub-tabla th { background: #f3f5f9; font-size: 11px; position: static; }
table.sub-tabla td, table.sub-tabla th { padding: 4px 8px; }
table.sub-tabla tr.cerrada td { color: var(--muted); }
table.sub-tabla td.adtr-cel { line-height: 1.35; min-width: 170px; }
table.sub-tabla tr.fila-buscar td { background: #fff8e6; }
.buscar { line-height: 1.4; min-width: 190px; }
.buscar .badge-buscar { display: inline-block; background: #b45309; color: #fff; font-weight: 700; letter-spacing: .06em; font-size: 11px;
  padding: 2px 8px; border-radius: 4px; margin-bottom: 3px; }
.buscar.solo-especial .badge-buscar { background: var(--bad); }
.buscar button { margin-top: 4px; }
.buscar .lugar { margin-bottom: 4px; }
.manual-btns { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.buscar .lugar button { margin: 2px 0 0 0; display: block; }
.sep-reg { line-height: 1.4; margin-bottom: 4px; }
.sep-hecho { line-height: 1.4; margin-bottom: 4px; }
.sep-reg button.link { border: 0; background: none; color: var(--bad); padding: 0 2px; text-decoration: underline; cursor: pointer; }
.pie-orden { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--warn-soft); border: 1px solid #f3d08a;
  border-radius: 6px; padding: 6px 10px; margin-bottom: 6px; }
table.cascada td.acciones { white-space: nowrap; }
table.cascada td.acciones button + button { margin-left: 4px; }
table.sub-tabla td.adtr-cel .badge { margin-bottom: 2px; }
table.sub-tabla tr.cerrada td.code { text-decoration: line-through; }
.ing-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.ing-card > header { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--soft); border-radius: 8px 8px 0 0; }
.ing-card > footer { display: flex; gap: 10px; align-items: center; padding: 8px 14px; flex-wrap: wrap; }
.code { font-family: Consolas, "Courier New", monospace; font-weight: 600; }
/* modales */
#modals .backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 1180px; }
.modal > header { padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal > header h3 { margin: 0; flex: 1; font-size: 16px; }
.modal > .body { padding: 14px 18px; }
.modal > footer { padding: 10px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #17233b; color: #fff; padding: 10px 14px; border-radius: 6px; max-width: 460px; box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
/* login */
#login { position: fixed; inset: 0; background: #17233b; display: flex; align-items: center; justify-content: center; }
#login .box { background: #fff; border-radius: 10px; padding: 26px 28px; width: 360px; max-width: calc(100% - 32px); }
#login .box h2 { margin-top: 0; }
#login input { width: 100%; margin-bottom: 10px; }
/* informes */
.report-preview { background: #fff; border: 1px solid var(--line); padding: 18px; max-width: 210mm; margin: 0 auto; }
.rep { font-size: 11.5px; color: #000; }
.rep h1 { font-size: 15px; margin: 0 0 2px; }
.rep .rep-meta { font-size: 11px; color: #333; margin-bottom: 8px; }
.rep .grp { margin: 10px 0 14px; break-inside: avoid-page; }
.rep .grp-h { border: 1.5px solid #000; padding: 4px 8px; font-weight: 600; display: flex; flex-wrap: wrap; gap: 4px 16px; background: #f0f0f0; }
.rep .grp-h .big { font-size: 13.5px; }
.rep table { width: 100%; border-collapse: collapse; }
.rep th, .rep td { border: 1px solid #555; padding: 3px 5px; font-size: 11px; position: static; background: none; color: #000; }
.rep th { background: #e6e6e6; }
.rep .chk { width: 18px; text-align: center; }
.rep .box { display: inline-block; width: 12px; height: 12px; border: 1.3px solid #000; }
.rep .page { break-after: page; }
.rep .sign { margin-top: 18px; display: flex; gap: 40px; font-size: 11px; }
.rep .sign div { border-top: 1px solid #000; padding-top: 3px; min-width: 200px; }
#print-area { display: none; }
@page { size: A4; margin: 12mm 10mm; }
@media print {
  body.printing #app, body.printing #modals, body.printing #toasts, body.printing #login { display: none !important; }
  body.printing #print-area { display: block; }
  body { background: #fff; }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; min-height: 100vh; }
  #topbar { grid-column: 1; flex-wrap: wrap; padding: 8px 16px; }
  #sidebar { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 0; }
  #sidebar .sec { display: none; }
  #sidebar a { white-space: nowrap; }
  #view { padding: 14px 16px 60px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* recepción: búsqueda / escaneo */
[hidden] { display: none !important; }
tr.flash td { background: var(--warn-soft); transition: background .3s; }

.ing-card > summary { cursor: pointer; list-style: none; padding: 8px 12px; display: flex; align-items: center; gap: 6px; }
.ing-card > summary > header { flex: 1; padding: 0 !important; border: 0 !important; background: none !important; }
.ing-card > summary::-webkit-details-marker { display: none; }
.ing-card > summary::before { content: '▸ '; color: var(--muted, #888); }
.ing-card[open] > summary::before { content: '▾ '; }
.ing-card .big { font-size: 1.1em; font-weight: 700; }
.sec-sin > h2 { color: var(--bad); }

/* aviso de una línea de remito: ícono grande, el texto se ve al hacer clic */
.aviso > summary { list-style: none; cursor: pointer; font-size: 22px; line-height: 1; color: var(--warn); display: inline-block; margin-top: 2px; }
.aviso > summary::-webkit-details-marker { display: none; }
.aviso { position: relative; }
.aviso > div { position: absolute; z-index: 20; left: 0; top: 100%; width: 280px; margin-top: 4px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--warn); background: var(--warn-soft); color: var(--warn); box-shadow: 0 4px 14px rgba(0,0,0,.15); }
/* «⚠» del stock compartido: junto a «N en stock»; el detalle se abre hacia la izquierda (columna de la derecha) */
.aviso.compartido { display: inline-block; margin-left: 6px; vertical-align: middle; }
.aviso.compartido > summary { margin-top: 0; }
.aviso.compartido > div { left: auto; right: 0; width: 320px; text-align: left; }
