:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e5ea;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --pend-bg: #fef3c7;
  --parc-bg: #dbeafe;
  --camb-bg: #dcfce7;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d23;
    --text: #e8eaed;
    --muted: #9aa0a8;
    --line: #2c3038;
    --primary: #14b8a6;
    --primary-text: #04201d;
    --ok: #22c55e;
    --danger: #f87171;
    --pend-bg: #3b2f0b;
    --parc-bg: #172a4a;
    --camb-bg: #12321f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--primary); color: var(--primary-text);
}
.top h1 { font-size: 20px; margin: 0; }
.stats { font-size: 13px; opacity: .95; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }
.tab { display: none; }
.tab.active { display: block; }
.sub { margin: 20px 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* Barra inferior */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; color: var(--muted);
  padding: 8px 0 10px; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button span { font-size: 20px; }
.tabs button.on { color: var(--primary); font-weight: 600; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn.sm { min-height: 38px; padding: 0 12px; }

input, select {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 0; }
label > input, label > select { margin-top: 4px; color: var(--text); }
label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); }
label.check input { width: auto; min-height: 0; margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 14px 0 0; padding: 4px 12px 12px; }
legend { font-size: 13px; font-weight: 600; padding: 0 6px; }
fieldset.cambio { background: color-mix(in srgb, var(--camb-bg) 50%, transparent); }

.inline-form { display: flex; gap: 8px; margin: 10px 0; }
.inline-form input { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 8px; }
.row.gap { gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 10px; padding: 3px; margin: 10px 0; }
.seg button { border: 0; background: transparent; color: var(--text); min-height: 40px; border-radius: 8px; font: inherit; font-weight: 600; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); color: var(--primary); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 14px; }
.chips button.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* Escáner */
.reader { border-radius: var(--radius); overflow: hidden; background: #000; display: none; }
.reader.on { display: block; }
.reader video { width: 100% !important; display: block; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card h3 { margin: 0 0 6px; }
.card.last .name { font-size: 18px; }
.flash { animation: flash .5s ease; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--primary); } to { box-shadow: 0 0 0 0 transparent; } }
.qty { font-size: 22px; font-weight: 700; margin: 6px 0 2px; }
.qty.sm { font-size: 17px; }
.qty small { font-size: 13px; color: var(--muted); font-weight: 500; }

/* Listas */
.list { list-style: none; margin: 8px 0; padding: 0; }
.list li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.list li.item { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.list li.item.pendiente { border-left: 4px solid var(--warn); }
.list li.item.parcial { border-left: 4px solid #2563eb; }
.list li.item.cambiada { border-left: 4px solid var(--ok); opacity: .8; }
.list.compact li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 6px; }
.list.pick { max-height: 50vh; overflow: auto; }
.list.pick li { cursor: pointer; }
.list .empty { text-align: center; color: var(--muted); }
.nota { color: var(--muted); margin-top: 2px; }

.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.pendiente { background: var(--pend-bg); color: var(--warn); }
.badge.parcial { background: var(--parc-bg); color: #2563eb; }
.badge.cambiada { background: var(--camb-bg); color: var(--ok); }
@media (prefers-color-scheme: dark) {
  .badge.pendiente { color: #fbbf24; }
  .badge.parcial, .list li.item.parcial { color: #60a5fa; }
  .list li.item.parcial { color: inherit; border-left-color: #60a5fa; }
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }

/* Diálogo */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  border: 0; border-radius: 16px; padding: 18px;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { margin: 0 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20;
  font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

.login { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); }
.login h2 { margin: 0 0 12px; text-align: center; }

/* v2 */
[hidden] { display: none !important; }
.ctx { padding: 10px 12px; }
.ctx .seg { margin: 6px 0 0; }
.ctx-title { font-size: 13px; color: var(--muted); font-weight: 600; }
.ctx label { margin-top: 8px; }
.login input { margin-bottom: 10px; }
.back { padding-left: 4px; margin-bottom: 4px; }
.ico { font-size: 22px; width: 30px; text-align: center; }
.list li.hist { display: block; }
.delta { font-weight: 600; color: var(--primary); font-size: 13px; }
.hist-box { margin-top: 14px; }
.hist-box summary { cursor: pointer; font-weight: 600; color: var(--muted); padding: 6px 0; }
.check.esc span { font-size: 13px; }

/* Cajas de almacén */
.cajas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; margin: 12px 0; }
.caja-tile { background: var(--card); border: 2px solid var(--primary); border-radius: var(--radius); padding: 10px 8px; text-align: center; cursor: pointer; color: var(--text); font: inherit; }
.caja-tile .num { font-size: 32px; font-weight: 800; line-height: 1.1; color: var(--primary); }
.caja-tile .desc { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.caja-tile .cnt { font-size: 13px; font-weight: 600; margin-top: 2px; }
.caja-tile.vacia { border-style: dashed; border-color: var(--line); }
.caja-tile.vacia .num { color: var(--muted); }
.caja-tile.sin { border-color: var(--warn); }
.caja-tag { display: inline-block; background: var(--primary); color: var(--primary-text); font-weight: 700; font-size: 12px; border-radius: 6px; padding: 1px 7px; margin-right: 4px; }
.caja-head { display: flex; align-items: center; gap: 14px; }
.caja-head .num { font-size: 48px; font-weight: 800; color: var(--primary); line-height: 1; }
.ctx .caja-sel select { font-weight: 700; }
.tabs button { font-size: 11px; }
.grid2 > .full, .grid2 > label.full { grid-column: 1 / -1; }
