/* Layout: una columna de trabajo pensada para handheld vertical (≈480–720 DIP),
   barra superior con el conteo activo y barra de pestañas inferior fija.
   Paleta: verde bodega sobre grises fríos; estados con color semántico aparte. */
:root {
  --bg: #EEF2F0;
  --surface: #FFFFFF;
  --surface-2: #F5F8F6;
  --ink: #13201C;
  --muted: #56665F;
  --line: #D3DCD8;
  --accent: #0B6B57;
  --accent-ink: #FFFFFF;
  --accent-soft: #DBEEE8;
  --ok: #1D7433;
  --ok-soft: #E0F2E4;
  --warn: #8F5400;
  --warn-soft: #FCEFD7;
  --bad: #B42318;
  --bad-soft: #FDE3E0;
  --focus: #F2B600;
  --shadow: 0 1px 2px rgba(19, 32, 28, .08), 0 4px 16px rgba(19, 32, 28, .06);
  --font: "Segoe UI", "Segoe UI Variable", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", ui-monospace, monospace;
  --r: 10px;
  --tap: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D1412; --surface: #151F1C; --surface-2: #1B2723; --ink: #E5EEEA; --muted: #9AADA6; --line: #2A3833;
    --accent: #3CC09E; --accent-ink: #03221A; --accent-soft: #143A31;
    --ok: #5BCF7A; --ok-soft: #16321F; --warn: #E8A73A; --warn-soft: #382A10; --bad: #FF7B6D; --bad-soft: #3D1B18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D1412; --surface: #151F1C; --surface-2: #1B2723; --ink: #E5EEEA; --muted: #9AADA6; --line: #2A3833;
  --accent: #3CC09E; --accent-ink: #03221A; --accent-soft: #143A31;
  --ok: #5BCF7A; --ok-soft: #16321F; --warn: #E8A73A; --warn-soft: #382A10; --bad: #FF7B6D; --bad-soft: #3D1B18;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 var(--font); -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; text-wrap: balance; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Formularios ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; letter-spacing: .01em; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid var(--accent-soft); outline-offset: 0; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
input[type="file"] { padding: 8px; }
.field { display: flex; flex-direction: column; min-width: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 150px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 500; color: var(--ink); font-size: 1rem; margin: 0; }
.form-error { color: var(--bad); font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 16px; border-radius: 8px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { min-height: 38px; padding: 6px 10px; font-size: .9rem; }
.btn.block { width: 100%; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 24px;
  display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow);
}
.login-card input { margin-bottom: 8px; }
.login-card .btn { margin-top: 8px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; color: var(--accent); }
.brand h1 { color: var(--ink); }

/* ---------- Estructura ---------- */
.app { display: flex; flex-direction: column; min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.conteo-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 10px; padding: 6px 10px; min-height: 52px;
  color: var(--ink); font: inherit; cursor: pointer;
}
.chip-num {
  flex: none; width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center;
  background: var(--muted); color: var(--surface); font-weight: 800; font-size: 1rem; letter-spacing: .02em;
}
.conteo-chip.activo .chip-num { background: var(--accent); color: var(--accent-ink); }
.chip-text { min-width: 0; display: flex; flex-direction: column; }
.chip-text strong, .chip-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-text small { color: var(--muted); }
.topbar-user { display: flex; flex-direction: column; align-items: flex-end; font-size: .9rem; font-weight: 600; max-width: 35%; }
.topbar-user span, .topbar-user small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.banner { padding: 10px 16px; background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: .92rem; border-bottom: 1px solid var(--line); }
.banner button { margin-left: 6px; }

.view { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding-block: 14px 110px; padding-inline: 16px; outline: none; display: flex; flex-direction: column; gap: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; min-height: 62px;
  background: none; border: 0; color: var(--muted); font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* ---------- Tarjetas y secciones ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.empty { padding: 22px 14px; text-align: center; color: var(--muted); border: 1.5px dashed var(--line); border-radius: var(--r); display: flex; flex-direction: column; gap: 10px; align-items: center; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.kpi b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .78rem; color: var(--muted); font-weight: 600; }

/* ---------- Captura ---------- */
.scan-input {
  font-family: var(--mono); font-size: 1.45rem; min-height: 62px; letter-spacing: .02em;
  border-width: 2px; border-color: var(--accent);
}
.qty-input { font-size: 1.6rem; min-height: 62px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.prod {
  border-radius: var(--r); padding: 12px 14px; background: var(--accent-soft); display: flex; flex-direction: column; gap: 6px;
  border-left: 5px solid var(--accent);
}
.prod.no-maestro { background: var(--warn-soft); border-left-color: var(--warn); }
.prod-desc { font-size: 1.12rem; font-weight: 700; }
.prod-codes { display: flex; flex-wrap: wrap; gap: 4px 14px; font-family: var(--mono); font-size: .88rem; color: var(--muted); }
.prod-nums { display: flex; gap: 18px; flex-wrap: wrap; font-size: .92rem; }
.prod-nums b { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.hint-keys { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--muted); }
kbd { font-family: var(--mono); font-size: .78rem; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); color: var(--ink); }

.list { display: flex; flex-direction: column; }
.li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); align-items: center; }
.li:last-child { border-bottom: 0; }
.li-main { min-width: 0; }
.li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-sub { font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.li-qty { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.li.anulada .li-title, .li.anulada .li-qty { text-decoration: line-through; color: var(--muted); }
.li-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
/* D39: vista agrupada de la captura */
.ult-card { margin: 8px 0 4px; padding: 10px 12px; border: 2px solid var(--accent); background: var(--accent-soft); border-radius: 10px; }
.ult-desc { font-weight: 700; font-size: 1rem; line-height: 1.25; }
.ult-fila { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.ult-total { font-size: 2.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.ult-info { font-size: .85rem; color: var(--muted); }
.rafaga-det { flex-basis: 100%; }
.rafaga-det > summary { list-style: none; display: inline-flex; cursor: pointer; }
.rafaga-det > summary::-webkit-details-marker { display: none; }
.rafaga-det[open] > summary { margin-bottom: 4px; }
.rafaga-det .list { border-left: 3px solid var(--line); padding-left: 8px; }
.sug { width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.sug:hover, .sug:focus { border-color: var(--accent); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.mono { font-size: .84rem; white-space: nowrap; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 9px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--surface); color: var(--muted); font: inherit; font-weight: 700; padding: 9px 14px; min-height: 44px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Inventarios ---------- */
.conteos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.conteo-box { border: 1.5px solid var(--line); border-radius: 9px; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; background: var(--surface-2); }
.conteo-box.abierto { border-color: var(--accent); background: var(--accent-soft); }
.conteo-box .cn { font-weight: 800; font-size: 1.1rem; }
.conteo-box .btn { width: 100%; }
.conteo-box .pill { white-space: normal; }
@media (max-width: 460px) { .conteos { grid-template-columns: 1fr; } .kpis { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Menú "Más" ---------- */
.menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.menu .btn { justify-content: flex-start; min-height: 58px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(8, 14, 12, .55); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); color: var(--ink); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 140px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 120; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 10px; font-weight: 700; box-shadow: var(--shadow); background: var(--ink); color: var(--surface); }
.toast.ok { background: var(--ok); color: #fff; }
.toast.error { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }

.flash-ok { animation: flashOk .5s ease-out; }
.flash-bad { animation: flashBad .6s ease-out; }
@keyframes flashOk { from { box-shadow: 0 0 0 6px var(--ok); } to { box-shadow: 0 0 0 0 transparent; } }
@keyframes flashBad { from { box-shadow: 0 0 0 6px var(--bad); } to { box-shadow: 0 0 0 0 transparent; } }
/* Lista de líneas / grupos para el alcance del inventario */
.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 14px; max-height: 300px; overflow: auto; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; }
.chk-grid .check { min-height: 40px; font-size: .95rem; }
.opciones-radio { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
/* Avance de la lista de reconteo */
.lista-card { border-left: 5px solid var(--accent); }
.barra { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 6px 0 10px; }
.barra span { display: block; height: 100%; background: var(--accent); transition: width .2s; }

/* D40: cámara */
.scan-wrap { display: flex; gap: 8px; align-items: stretch; }
.scan-wrap .scan-input { flex: 1 1 auto; min-width: 0; }
.cam-btn { flex: 0 0 auto; width: 62px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.cam-btn svg { width: 28px; height: 28px; }
.cam-ov { position: fixed; inset: 0; z-index: 110; background: #000; color: #fff; }
.cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-guia { position: absolute; left: 8%; right: 8%; top: 36%; height: 22%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
.cam-guia span { position: absolute; left: 6%; right: 6%; top: 50%; border-top: 2px solid #ff4d4d; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px; background: linear-gradient(rgba(0,0,0,.65), rgba(0,0,0,0)); }
.cam-estado { font-weight: 700; font-size: .95rem; }
.cam-btns { display: flex; gap: 6px; }
.cam-pie { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 12px calc(16px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.75)); }
.cam-ult:empty { display: none; }
.cam-ult { background: rgba(255,255,255,.95); color: #111; border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
.cam-ult .ult-info { color: #444; }
.cam-ayuda { margin: 0; font-size: .85rem; opacity: .9; }

