/* Layout: una columna tipo app (máx. 480px), cabecera fija arriba, barra de pestañas fija abajo. Paleta "frío": escarcha + azul de cámara. */
:root {
  --bg: #eef3f6;
  --surface: #ffffff;
  --surface-2: #f6f9fb;
  --ink: #0e1c25;
  --muted: #566874;
  --line: #d3dde4;
  --accent: #0a6a86;
  --accent-ink: #ffffff;
  --accent-soft: #d9edf3;
  --good: #2b7a4b;
  --good-soft: #dcefe3;
  --warn: #a8660b;
  --warn-soft: #fbecd2;
  --crit: #b8322e;
  --crit-soft: #f8dddc;
  --track: #e1e8ed;
  --shadow: 0 1px 2px rgba(14, 28, 37, .06), 0 4px 16px rgba(14, 28, 37, .06);
  --f-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1318; --surface: #13212a; --surface-2: #182a35; --ink: #e4edf2; --muted: #93a6b1; --line: #263a46;
    --accent: #4fb6d3; --accent-ink: #04212b; --accent-soft: #123b4a; --good: #5cc58a; --good-soft: #143826;
    --warn: #e9a945; --warn-soft: #3d2b0e; --crit: #f07a74; --crit-soft: #42191a; --track: #213440;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1318; --surface: #13212a; --surface-2: #182a35; --ink: #e4edf2; --muted: #93a6b1; --line: #263a46;
  --accent: #4fb6d3; --accent-ink: #04212b; --accent-soft: #123b4a; --good: #5cc58a; --good-soft: #143826;
  --warn: #e9a945; --warn-soft: #3d2b0e; --crit: #f07a74; --crit-soft: #42191a; --track: #213440;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); }
body { color: var(--ink); font-family: var(--f-sans); font-size: 16px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.num, .mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.app { max-width: 480px; margin: 0 auto; min-height: 100vh; background: var(--bg); display: flex; flex-direction: column; }

/* Cabecera */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.brand .glyph { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--f-mono); font-size: 13px; font-weight: 600; }
.pill { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 10px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.pill.off { background: var(--warn-soft); border-color: var(--warn); }
.pill.off .dot { background: var(--warn); }

main { flex: 1; padding-block: 16px 112px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 16px; }
h1 { font-size: 22px; margin: 0; line-height: 1.2; text-wrap: balance; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 8px 0 0; font-weight: 600; }
.sub { color: var(--muted); font-size: 14px; margin: 2px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.demo { font-size: 13px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; display: flex; gap: 8px; align-items: center; }
.demo button { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px 0; margin-left: auto; font-size: 13px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi .v { font-family: var(--f-mono); font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.kpi .s { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }

/* Barras de ocupación */
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 84px 1fr auto; gap: 10px; align-items: center; padding: 8px 4px; border: 0; background: none; text-align: left; border-radius: 8px; min-height: 44px; }
.bar-row:hover { background: var(--surface-2); }
.track { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
.fill { height: 100%; border-radius: 5px; background: var(--accent); min-width: 3px; }
.bar-row .num { font-size: 13px; color: var(--muted); }

/* Alertas */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 14.5px; text-align: left; width: 100%; }
.alert .tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; flex: none; margin-top: 2px; }
.alert.warn { border-color: var(--warn); background: var(--warn-soft); }
.alert.warn .tag { background: var(--warn); color: var(--surface); }
.alert.crit { border-color: var(--crit); background: var(--crit-soft); }
.alert.crit .tag { background: var(--crit); color: var(--surface); }
.alert.info .tag { background: var(--accent-soft); color: var(--accent); }
button.alert { cursor: pointer; }

/* Listas */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; width: 100%; min-height: 56px; }
.item:first-child { border-top: 0; }
button.item:hover { background: var(--surface-2); }
.item .t { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.item .d { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.item .r { text-align: right; flex: none; }
.item .r .num { font-size: 15px; font-weight: 600; }
.empty { padding: 20px 14px; color: var(--muted); font-size: 14px; text-align: center; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.b-ENTRADA { background: var(--good-soft); color: var(--good); border-color: transparent; }
.b-SALIDA { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.b-CAMBIO { background: var(--surface-2); color: var(--ink); }
.b-DEVOLUCIÓN { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.b-ANULACIÓN { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.b-pend { background: var(--warn); color: var(--surface); border-color: transparent; }
.strike .t { text-decoration: line-through; color: var(--muted); }

/* Lotes */
.lot { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 14px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; width: 100%; }
.lot:first-child { border-top: 0; }
.lot:hover { background: var(--surface-2); }
.lot .p { font-weight: 600; font-size: 15px; }
.lot .meta { font-size: 13px; color: var(--muted); grid-column: 1; }
.lot .qty { text-align: right; grid-row: 1 / span 2; grid-column: 2; }
.lot .qty .num { display: block; font-weight: 600; font-size: 15px; }
.lot .qty .kg { font-size: 12.5px; color: var(--muted); }
.lot .loc { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chip-s { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-family: var(--f-mono); }
.chip-s.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

/* Cámaras */
.cams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cam { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 108px; }
.cam:hover { border-color: var(--accent); }
.cam .n { font-weight: 700; font-size: 17px; }
.cam .pct { font-family: var(--f-mono); font-size: 24px; font-weight: 600; }
.cam .s { font-size: 12.5px; color: var(--muted); }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.fila { aspect-ratio: 1 / 1; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; position: relative; overflow: hidden; }
.fila .fn { font-family: var(--f-mono); font-weight: 600; font-size: 17px; position: relative; }
.fila .ff { font-size: 11px; color: var(--muted); font-family: var(--f-mono); position: relative; }
.fila .lvl { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent-soft); }
.fila.mid .lvl { background: var(--warn-soft); }
.fila.full .lvl { background: var(--crit-soft); }
.fila.full { border-color: var(--crit); }
.fila.sel { outline: 3px solid var(--accent); outline-offset: 1px; }
.fila.sug { border: 2px solid var(--good); }
.fila:disabled { opacity: .35; cursor: not-allowed; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--line); }

.back { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 0; display: inline-flex; gap: 4px; align-items: center; min-height: 44px; align-self: flex-start; }
.meter { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.meter div { background: var(--surface-2); border-radius: 10px; padding: 10px 4px; }
.meter .v { font-family: var(--f-mono); font-weight: 600; font-size: 20px; display: block; }
.meter .l { font-size: 12px; color: var(--muted); }

/* Botones */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 16px; font-weight: 600; min-height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--crit); border-color: var(--crit); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; }
.ops { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.op { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 16px 14px; min-height: 112px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left; gap: 8px; box-shadow: var(--shadow); }
.op:hover { border-color: var(--accent); }
.op .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.op .ot { font-weight: 700; font-size: 17px; }
.op .od { font-size: 13px; color: var(--muted); }
.op.wide { grid-column: 1 / -1; min-height: 0; flex-direction: row; align-items: center; }
.op .cnt { margin-left: auto; font-family: var(--f-mono); font-weight: 600; background: var(--warn); color: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 15px; }
.op[disabled] { opacity: .4; cursor: not-allowed; }

/* Asistente */
.wiz-head { display: flex; align-items: center; gap: 8px; }
.steps { display: flex; gap: 4px; }
.steps span { height: 4px; flex: 1; border-radius: 2px; background: var(--track); }
.steps span.on { background: var(--accent); }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.choices.sm { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.choice { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; min-height: 52px; text-align: left; font-weight: 500; font-size: 15px; overflow-wrap: anywhere; }
.choice.on { border: 2px solid var(--accent); background: var(--accent-soft); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .lbl { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.input { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px; min-height: 52px; font-size: 17px; width: 100%; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; align-items: center; }
.stepper button { height: 56px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 24px; font-weight: 600; }
.stepper input { text-align: center; font-family: var(--f-mono); font-size: 22px; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }
.hint.err { color: var(--crit); font-weight: 600; }
.total { display: flex; justify-content: space-between; align-items: baseline; background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; }
.total .num { font-size: 22px; font-weight: 600; }
.summary { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 15px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.wiz-foot { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 10px; padding-top: 8px; background: linear-gradient(to bottom, transparent, var(--bg) 30%); }
.wiz-foot .btn { flex: 1; }
.search { position: relative; }

/* Barra de pestañas */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
.tabs nav { max-width: 480px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tab { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; font-size: 11.5px; font-weight: 500; color: var(--muted); min-height: 64px; position: relative; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--accent); font-weight: 700; }
.tab.center .ring { width: 48px; height: 48px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-top: -18px; box-shadow: var(--shadow); }
.tab.center.on { color: var(--accent); }
.tab .b { position: absolute; top: 4px; right: calc(50% - 26px); background: var(--warn); color: var(--surface); font-size: 11px; font-weight: 700; border-radius: 999px; padding: 0 6px; font-family: var(--f-mono); }

/* Hoja inferior */
.scrim { position: fixed; inset: 0; background: rgba(5, 15, 20, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; max-height: 88vh; overflow: auto; padding-block: 16px calc(20px + env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 14px; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); align-self: center; }

.palnum { display: inline-block; min-width: 26px; padding: 1px 7px; margin-right: 8px; border-radius: 999px; background: var(--ink); color: var(--bg); text-align: center; font-weight: 700; font-size: 14px; }
.input[aria-invalid="true"] { border-color: var(--crit); outline-color: var(--crit); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 30; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14.5px; font-weight: 500; max-width: calc(100% - 32px); width: max-content; box-shadow: var(--shadow); }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: up .2s ease-out; }
  .sheet { animation: up .2s ease-out; }
  @keyframes up { from { transform: translate(var(--tx, 0), 12px); opacity: 0; } }
  .toast { --tx: -50%; }
}
