:root {
  /* Identidad Industrias Space: azul marino del emblema, rojo de SPACE, gris carbón de INDUSTRIAS */
  --bg: #F3F5F8; --surface: #FFFFFF; --surface-2: #EEF2F6; --border: #D9E0E8; --text: #27242B; --muted: #5E6672;
  --primary: #144A74; --primary-2: #1D5E93; --on-primary: #FFFFFF; --accent: #BA2735; --accent-2: #9E1F2C; --on-accent: #FFFFFF;
  --ok: #1E7A46; --ok-bg: #E4F4EA; --warn: #9A6400; --warn-bg: #FFF4D6; --err: #B42318; --err-bg: #FDE8E7; --info: #1D5FA8; --info-bg: #E5EFFB;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08); --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif; --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F141B; --surface: #161D27; --surface-2: #1D2633; --border: #2A3545; --text: #E6EBF2; --muted: #9AA7B8;
    --primary: #6EA6D8; --primary-2: #8DBBE4; --on-primary: #0B1220; --accent: #E5596A; --accent-2: #F07A88; --on-accent: #1A0B0E;
    --ok: #5CCB8A; --ok-bg: #12301F; --warn: #F2C14E; --warn-bg: #3A2E0E; --err: #F28B82; --err-bg: #3B1614; --info: #8AB8F0; --info-bg: #13263F;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F141B; --surface: #161D27; --surface-2: #1D2633; --border: #2A3545; --text: #E6EBF2; --muted: #9AA7B8;
  --primary: #6EA6D8; --primary-2: #8DBBE4; --on-primary: #0B1220; --accent: #E5596A; --accent-2: #F07A88; --on-accent: #1A0B0E;
  --ok: #5CCB8A; --ok-bg: #12301F; --warn: #F2C14E; --warn-bg: #3A2E0E; --err: #F28B82; --err-bg: #3B1614; --info: #8AB8F0; --info-bg: #13263F;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--primary-2); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); } .right { text-align: right; } .center { text-align: center; }
.nowrap { white-space: nowrap; } .grow { flex: 1; } .hidden { display: none !important; }

/* Layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 700; letter-spacing: .5px; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.brand small { display: block; font-weight: 400; color: var(--muted); letter-spacing: 0; font-size: 11px; }
/* Logo completo sobre placa blanca (el logo es de fondo blanco; se ve bien también en modo oscuro) */
.brand.logo { flex-direction: column; align-items: stretch; gap: 6px; padding: 0 0 14px; margin-bottom: 4px; border-bottom: 3px solid var(--accent); }
.brand.logo .plate { background: #FFFFFF; border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); }
.brand.logo img { width: 100%; height: auto; border-radius: 0; display: block; }
.brand.logo small { text-align: center; text-transform: uppercase; letter-spacing: 2px; font-weight: 700; color: var(--primary); font-size: 10px; }
.nav-group { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; letter-spacing: .6px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary); color: var(--on-primary); box-shadow: inset 4px 0 0 var(--accent); }
.nav .badge { margin-left: auto; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .search { flex: 1; max-width: 560px; position: relative; }
.content { padding: 20px; max-width: 1400px; }
.btn.menu-btn { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 50; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 14px 16px; }
  .topbar { padding: 8px 16px; }
  .hide-sm { display: none; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 14px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 36px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 4px 9px; min-height: 28px; font-size: 12px; }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { border-color: transparent; background: transparent; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field { min-width: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 36px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--primary-2); outline-offset: 1px; }
input[type=checkbox] { width: auto; min-height: 0; }
input.qty { width: 84px; text-align: right; }
textarea { min-height: 64px; resize: vertical; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-warn { background: var(--warn-bg); color: var(--warn); } .b-err { background: var(--err-bg); color: var(--err); } .b-info { background: var(--info-bg); color: var(--info); }
.msg { padding: 10px 12px; border-radius: 8px; border: 1px solid transparent; white-space: pre-line; }
.msg.err { background: var(--err-bg); color: var(--err); border-color: var(--err); } .msg.warn { background: var(--warn-bg); color: var(--warn); } .msg.ok { background: var(--ok-bg); color: var(--ok); } .msg.info { background: var(--info-bg); color: var(--info); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .s { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tabs button { background: none; border: none; padding: 8px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--primary-2); border-bottom-color: var(--primary-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* Autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 320px; overflow-y: auto; z-index: 40; }
.ac-item { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.ac-item.on, .ac-item:hover { background: var(--surface-2); }
.ac-item .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Modal / toasts */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,25,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { max-width: 980px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); white-space: pre-line; }
.toast.err { background: var(--err); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .bar { width: 45%; max-width: 14px; border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .lbl { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.c-in { background: var(--ok); } .c-out { background: var(--primary-2); }
.hbar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; } .hbar > i { display: block; height: 100%; background: var(--primary-2); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 400px; border-top: 4px solid var(--accent); }
.login { background: linear-gradient(160deg, var(--bg) 0%, var(--bg) 60%, color-mix(in srgb, var(--primary) 12%, var(--bg)) 100%); }
.login .brand.logo { border-bottom: 0; padding-bottom: 4px; }
.login .brand.logo .plate { box-shadow: none; padding: 4px 0 10px; }
.success-box { text-align: center; padding: 24px; }
.success-box .num { font-size: 28px; font-weight: 800; color: var(--ok); margin: 6px 0; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: var(--surface-2); }
.matrix input { width: 64px; text-align: right; padding: 6px; }
.matrix td, .matrix th { padding: 4px; text-align: center; }
video.scan { width: 100%; max-height: 320px; background: #000; border-radius: 8px; }
.sticky-foot { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 12px 16px; margin: 14px -16px -16px; border-radius: 0 0 var(--radius) var(--radius);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Existencias por referencia: tallas en columnas */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
table.matrix th.num, table.matrix td.num { min-width: 34px; padding-left: 6px; padding-right: 6px; text-align: right; }
table.matrix td:first-child, table.matrix th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.matrix tbody tr:hover td { background: var(--surface-2); }
table.matrix th:not(.num), table.matrix td:not(.num) { text-align: left; white-space: nowrap; }

/* Acentos de marca */
.page-head h1 { position: relative; padding-bottom: 6px; }
.page-head h1::after { content: ""; position: absolute; left: 0; bottom: 0; width: 36px; height: 3px; border-radius: 2px; background: var(--accent); }
.btn.danger-brand, .btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
thead th { border-bottom: 2px solid var(--primary); }

/* Pedidos: tablero de etapas */
.pipeline { display: flex; align-items: stretch; gap: 6px; flex-wrap: wrap; }
.pipeline .stage { display: flex; flex-direction: column; align-items: flex-start; gap: 0; min-width: 104px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.pipeline .stage .n { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pipeline .stage .l { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.pipeline .stage:hover { border-color: var(--primary-2); }
.pipeline .stage.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pipeline .stage.on .l { color: var(--on-primary); }
.pipeline .stage.done .n { color: var(--ok); } .pipeline .stage.warn .n { color: var(--warn); } .pipeline .stage.err .n { color: var(--err); }
.pipeline .stage.on .n { color: var(--on-primary); }
.pipeline .arrow { align-self: center; color: var(--muted); font-size: 20px; }
.pipeline .sep { flex: 1; min-width: 8px; }
@media (max-width: 860px) { .pipeline .arrow, .pipeline .sep { display: none; } .pipeline .stage { min-width: calc(50% - 4px); } }
.progress { display: flex; align-items: center; gap: 6px; min-width: 110px; } .progress .hbar { flex: 1; min-width: 50px; }
input.qty.price { width: 110px; }

/* Pedidos: recorrido (barra de etapas) */
.stepper { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; }
.stepper .step { position: relative; text-align: center; padding: 0 6px; }
.stepper .step::before { content: ""; position: absolute; top: 15px; left: calc(-50% + 18px); right: calc(50% + 18px); height: 3px; background: var(--border); }
.stepper .step:first-child::before { display: none; }
.stepper .step.done::before, .stepper .step.partial::before { background: var(--ok); }
.stepper .dot { width: 32px; height: 32px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--surface-2); color: var(--muted); border: 2px solid var(--border); position: relative; z-index: 1; }
.stepper .step.done .dot { background: var(--ok); color: #fff; border-color: var(--ok); }
.stepper .step.partial .dot { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.stepper .step.current .dot { border-color: var(--primary-2); color: var(--primary-2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary-2) 20%, transparent); }
.stepper .lbl { font-weight: 700; font-size: 13px; }
@media (max-width: 640px) { .stepper .lbl { font-size: 11px; } .stepper .small { display: none; } }
.next-step { margin-top: 14px; border-left: 4px solid var(--primary-2); }
.next-step.st-REPROGRAMADO { border-left-color: var(--err); } .next-step.st-ENTREGADO { border-left-color: var(--ok); } .next-step.st-CANCELADO { border-left-color: var(--muted); }

/* Pedidos: línea de tiempo */
.timeline { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow-y: auto; }
.timeline .ev { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline .ev:last-child { border-bottom: 0; }
.timeline .ic { flex: 0 0 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--primary-2); font-weight: 800; }
.timeline .ev-DESPACHO .ic, .timeline .ev-ENTREGA .ic, .timeline .ev-APROBADO .ic { background: var(--ok-bg); color: var(--ok); }
.timeline .ev-REPROGRAMADO .ic, .timeline .ev-CANCELADO .ic, .timeline .ev-SALDO_CANCELADO .ic { background: var(--err-bg); color: var(--err); }
.timeline .small .badge { margin-left: 4px; }
.totals > div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.totals > div.grand { font-size: 18px; color: var(--primary-2); border-bottom: 0; }
.stepper.s4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stepper .step.late .dot { border-color: var(--err); color: var(--err); background: var(--err-bg); }
