/* ==========================================================================
   Escaner TQT — sistema visual "máscara de soldadura + serigrafía"
   Suelo azul-negro (máscara), texto hueso (serigrafía), acento oro (ENIG).
   Tokens en :root (claro) y redefinidos para oscuro. Sin dependencias de red.
   ========================================================================== */

/* ---------- tipografía local ---------- */
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 400; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 500; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 600; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 700; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-style: normal; font-display: swap; src: url("/static/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-style: normal; font-display: swap; src: url("/static/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-style: normal; font-display: swap; src: url("/static/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2"); }

/* ---------- tokens: claro ("papel serigrafía") ---------- */
:root {
  --bg: #E9ECF1;
  --bg-2: #DFE3EA;
  --surface: #FFFFFF;
  --surface-2: #F3F5F9;
  --line: #C5CDDB;
  --line-2: #69758F;
  --text: #0D1630;
  --muted: #4C5873;
  --faint: #5B6782;

  --accent: #C58B14;
  --accent-ink: #1B1303;
  --accent-text: #8A5B00;

  --ok: #066D42;
  --warn: #875100;
  --bad: #B42424;
  --info: #1D63C2;

  --r1: #1858B0;
  --r2: #6A38C8;
  --r3: #056660;

  --font-ui: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --r-1: 4px;
  --r-2: 8px;
  --gap: 12px;
  --gutter: 16px;
  --tap: 48px;
  --bar-h: 56px;
  --tab-h: 64px;
  --shadow: 0 1px 0 rgba(13, 22, 48, .06), 0 8px 24px -12px rgba(13, 22, 48, .25);
  color-scheme: light;
}

/* ---------- tokens: oscuro ("máscara de soldadura") ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A1020;
    --bg-2: #070B17;
    --surface: #121B33;
    --surface-2: #1A2646;
    --line: #26335A;
    --line-2: #5F72A6;
    --text: #E9EEF5;
    --muted: #93A1BD;
    --faint: #8290B4;
    --accent: #D9A441;
    --accent-ink: #1B1303;
    --accent-text: #E6B458;
    --ok: #3FD08A;
    --warn: #F2B33D;
    --bad: #FF6B6B;
    --info: #5AA9FF;
    --r1: #62A8FF;
    --r2: #B08CFF;
    --r3: #2FC9C0;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 10px 30px -14px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0A1020;
  --bg-2: #070B17;
  --surface: #121B33;
  --surface-2: #1A2646;
  --line: #26335A;
  --line-2: #5F72A6;
  --text: #E9EEF5;
  --muted: #93A1BD;
  --faint: #8290B4;
  --accent: #D9A441;
  --accent-ink: #1B1303;
  --accent-text: #E6B458;
  --ok: #3FD08A;
  --warn: #F2B33D;
  --bad: #FF6B6B;
  --info: #5AA9FF;
  --r1: #62A8FF;
  --r2: #B08CFF;
  --r3: #2FC9C0;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 10px 30px -14px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui); font-size: 16px; line-height: 1.35; font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono, code { font-family: var(--font-mono); font-variant-numeric: tabular-nums slashed-zero; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.svg-i { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* etiqueta serigráfica: texto pequeño en mayúsculas con trazo */
.silk {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); display: flex; align-items: center; gap: 10px;
}
.silk::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.silk > .n { color: var(--accent-text); }

/* ---------- estructura móvil ---------- */
.app { display: flex; flex-direction: column; min-height: 100dvh; max-width: 680px; margin: 0 auto; background: var(--bg); position: relative; }
.app > main { flex: 1; padding: 12px var(--gutter) calc(var(--tab-h) + 24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: var(--gap); }
.app.has-cta > main { padding-bottom: calc(var(--tab-h) + 96px + env(safe-area-inset-bottom, 0px)); }

.topbar {
  position: sticky; top: 0; z-index: 30; height: calc(var(--bar-h) + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) var(--gutter) 0;
  display: flex; align-items: center; gap: 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; text-decoration: none; color: var(--text); min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; color: var(--accent); }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .02em; line-height: 1; }
.brand > div { min-width: 0; }
.brand-name { display: block; white-space: nowrap; }
.brand-sub { display: block; font-family: var(--font-mono); font-size: 10px; font-weight: 500; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* encabezado móvil: el logo va a "/" y el sub-título (lote) es un botón que abre la hoja de lotes */
.brandbox { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "mark name" "mark sub"; column-gap: 10px; align-items: center; min-width: 0; }
.brandbox .brand-logo { grid-area: mark; display: grid; place-items: center; min-height: 44px; color: var(--accent); text-decoration: none; }
.brandbox .brand { grid-area: name; min-height: 0; align-self: end; }
button.brand-sub {
  grid-area: sub; justify-self: start; position: relative; display: inline-flex; align-items: center; gap: 2px; max-width: 100%; margin-top: 1px; padding: 0; border: 0; background: transparent; color: var(--muted);
  text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--line-2); cursor: pointer;
}
button.brand-sub > span { overflow: hidden; text-overflow: ellipsis; }
button.brand-sub .svg-i { width: 12px; height: 12px; flex: none; transform: rotate(90deg); stroke-width: 2.4; }
button.brand-sub::after { content: ""; position: absolute; inset: -12px -10px -14px -6px; }   /* zona táctil ≥ 44 px sin agrandar el texto */
button.brand-sub:hover { color: var(--text); }
.topbar .spacer { flex: 1; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; }
@media (max-width: 420px) { .conn[data-s="connected"] span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: block; }
.conn[data-s="connected"] i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.conn[data-s="connecting"] i { background: var(--warn); }
.conn[data-s="disconnected"] i, .conn[data-s="error"] i { background: var(--bad); }
.iconbtn { flex: none; width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: var(--r-1); border: 1px solid transparent; background: transparent; color: var(--text); }
.iconbtn:hover { background: var(--surface-2); }
.iconbtn:active { transform: translateY(1px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0 auto; max-width: 680px;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line-2);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; position: relative; min-width: 0; }
.tab .svg-i { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent-text); }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px; background: var(--accent); }

/* barra de acción fija (encima de la barra de pestañas) */
.cta-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); z-index: 35; margin: 0 auto; max-width: 680px;
  padding: 10px var(--gutter); background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ---------- botones ---------- */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: var(--r-1); border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: .02em; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); color: var(--bad); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn .count { font-family: var(--font-mono); font-weight: 600; padding: 2px 8px; border-radius: 3px; background: color-mix(in srgb, var(--accent-ink) 16%, transparent); }

/* ---------- formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .lbl { font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.input, select.input {
  width: 100%; min-height: var(--tap); padding: 0 12px; border-radius: var(--r-1); border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text); font-size: 16px;
}
.input.mono { font-family: var(--font-mono); font-size: 18px; letter-spacing: .04em; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.hint { font-size: 13px; color: var(--muted); }
.hint.err { color: var(--bad); }
.hint.ok { color: var(--ok); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line-2); border-radius: var(--r-1); overflow: hidden; background: var(--bg-2); }
.seg button { min-height: var(--tap); border: 0; background: transparent; font-weight: 700; color: var(--muted); border-right: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 8px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: var(--r-1); overflow: hidden; }
.stepper button { width: var(--tap); border: 0; background: var(--surface-2); font-size: 22px; font-weight: 700; }
.stepper input { width: 64px; text-align: center; border: 0; background: var(--bg-2); font-family: var(--font-mono); font-size: 20px; font-weight: 600; }

/* ---------- designadores de tipo (R1/R2/R3) ---------- */
.tipo {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-weight: 600; font-size: 12px; letter-spacing: .06em;
  padding: 3px 8px 3px 6px; border: 1px solid currentColor; border-radius: 3px; line-height: 1.2; color: var(--muted); background: color-mix(in srgb, currentColor 10%, transparent);
}
.tipo::before { content: ""; width: 8px; height: 8px; background: currentColor; flex: none; }
.tipo[data-t="R1"] { color: var(--r1); }
.tipo[data-t="R2"] { color: var(--r2); }
.tipo[data-t="R2"]::before { border-radius: 50%; }
.tipo[data-t="R3"] { color: var(--r3); }
.tipo[data-t="R3"]::before { transform: rotate(45deg) scale(.9); }
.tipo.lg { font-size: 15px; padding: 5px 12px 5px 9px; }
.tipo.lg::before { width: 10px; height: 10px; }
.tipo[data-empty="1"] { color: var(--faint); border-style: dashed; background: transparent; }

/* ---------- estados ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; padding: 3px 9px; border-radius: 3px;
  border: 1px solid currentColor; color: var(--muted); background: color-mix(in srgb, currentColor 11%, transparent); white-space: nowrap;
}
.badge[data-k="ok"] { color: var(--ok); }
.badge[data-k="warn"] { color: var(--warn); }
.badge[data-k="bad"] { color: var(--bad); }
.badge[data-k="info"] { color: var(--info); }
.badge[data-k="accent"] { color: var(--accent-text); }
.badge .svg-i { width: 13px; height: 13px; stroke-width: 2.4; }

/* ---------- tarjetas/paneles ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); }
.panel.pad { padding: 14px; }
.cut { clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%); border-radius: 0; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-1); border: 1px solid var(--line-2); background: var(--surface); font-size: 14px; }
.banner[data-k="warn"] { border-color: color-mix(in srgb, var(--warn) 60%, var(--line)); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.banner[data-k="bad"] { border-color: color-mix(in srgb, var(--bad) 60%, var(--line)); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); }
.banner[data-k="ok"] { border-color: color-mix(in srgb, var(--ok) 60%, var(--line)); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.banner .svg-i { margin-top: 2px; }
.banner[data-k="warn"] .svg-i { color: var(--warn); }
.banner[data-k="bad"] .svg-i { color: var(--bad); }
.banner[data-k="ok"] .svg-i { color: var(--ok); }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; border: 1px dashed var(--line-2); border-radius: var(--r-2); }
.empty .svg-i { width: 34px; height: 34px; color: var(--faint); stroke-width: 1.4; }
.empty b { color: var(--text); font-size: 17px; }

/* ---------- visor de cámara ---------- */
.visor {
  position: relative; background: #000; overflow: hidden; aspect-ratio: 4 / 3; width: 100%; max-height: 46dvh; min-height: 220px;
  clip-path: polygon(0 0, calc(100% - 22px) 0, 100% 22px, 100% 100%, 22px 100%, 0 calc(100% - 22px));
  outline: 1px solid var(--line-2);
}
.visor.compact { aspect-ratio: 16 / 9; max-height: 30dvh; min-height: 170px; }
/* móvil horizontal: el visor no se come toda la pantalla (quedan visibles lectura y contadores) */
@media (orientation: landscape) and (max-height: 480px) { .visor, .visor.compact { min-height: 110px; max-height: 34dvh; } }
.visor video { width: 100%; height: 100%; object-fit: cover; display: block; }
.visor .frame { position: absolute; inset: 14% 20% 14% 12%; pointer-events: none; }
.visor .frame i { position: absolute; width: 30px; height: 30px; border: 0 solid var(--accent); }
.visor .frame i:nth-child(1) { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; }
.visor .frame i:nth-child(2) { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; }
.visor .frame i:nth-child(3) { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; }
.visor .frame i:nth-child(4) { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; }
.visor .frame::after { content: ""; position: absolute; left: 4%; right: 4%; height: 2px; top: 0; background: var(--accent); box-shadow: 0 0 14px 2px color-mix(in srgb, var(--accent) 70%, transparent); opacity: .85; animation: sweep 2.6s ease-in-out infinite alternate; }
@keyframes sweep { to { top: calc(100% - 2px); } }
.visor[data-state="locked"] .frame::after, .visor[data-state="idle"] .frame::after, .visor[data-state="error"] .frame::after { animation: none; opacity: 0; }
.visor::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 0 transparent; transition: box-shadow .12s; }
.visor.fx-ok::after { box-shadow: inset 0 0 0 5px var(--ok); }
.visor.fx-warn::after { box-shadow: inset 0 0 0 5px var(--warn); }
.visor.fx-err::after { box-shadow: inset 0 0 0 5px var(--bad); }
.visor .tools { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 8px; }
.visor .tools .iconbtn { background: rgba(6, 10, 22, .68); color: #fff; border: 1px solid rgba(255, 255, 255, .22); backdrop-filter: blur(4px); }
.visor .tools .iconbtn.is-torch[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.visor .status { position: absolute; left: 10px; top: 10px; max-width: calc(100% - 76px); min-height: 44px; display: inline-flex; align-items: center; text-align: left; font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #fff; background: rgba(6, 10, 22, .68); padding: 4px 8px; border-radius: 3px; }
.visor .fail { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 20px; background: var(--bg-2); color: var(--text); }
.visor .fail b { font-size: 18px; }
.visor .fail p { color: var(--muted); font-size: 14px; max-width: 32ch; }
.visor .fail .svg-i { width: 34px; height: 34px; color: var(--faint); }

/* lectura serigráfica: el número recién leído, grande, como impreso en la placa */
.readout { position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 16px; padding: 12px 14px; border: 1px solid var(--line-2); border-radius: var(--r-1); background: var(--bg-2); min-height: 108px; }
.readout .silk { grid-column: 1 / -1; }
.readout .serie { font-family: var(--font-mono); font-weight: 600; font-size: clamp(56px, 20vw, 88px); line-height: .95; letter-spacing: .02em; font-variant-numeric: slashed-zero; }
.readout .meta { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.readout .name { font-family: var(--font-mono); font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.readout .msg { font-size: 15px; font-weight: 600; }
.readout[data-k="ok"] { border-color: var(--ok); }
.readout[data-k="warn"] { border-color: var(--warn); }
.readout[data-k="bad"] { border-color: var(--bad); }
.readout[data-k="ok"] .msg { color: var(--ok); }
.readout[data-k="warn"] .msg { color: var(--warn); }
.readout[data-k="bad"] .msg { color: var(--bad); }
.readout[data-idle="1"] .serie { color: var(--line-2); }

/* contadores por tipo */
.counters { display: grid; grid-template-columns: repeat(3, 1fr) 1.1fr; border: 1px solid var(--line); border-radius: var(--r-1); background: var(--surface); overflow: hidden; }
.counters > div { padding: 8px 10px 9px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.counters > div:last-child { border-right: 0; background: var(--surface-2); }
.counters .lbl { font-size: 10px; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 360px) { .counters .lbl { font-size: 9px; letter-spacing: 0; } }
.counters .n { font-family: var(--font-mono); font-size: 28px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.counters .n.bump { animation: bump .28s ease-out; }
@keyframes bump { 40% { transform: translateY(-3px); color: var(--accent-text); } }

/* ---------- listas ---------- */
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); overflow: hidden; }
.item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; min-height: 56px; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; width: 100%; color: inherit; }
.item:last-child { border-bottom: 0; }
button.item:hover, a.item:hover { background: var(--surface-2); }
.item .t1 { font-family: var(--font-mono); font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
.item .t2 { font-size: 13px; color: var(--muted); }
.item.enter { animation: rowin .32s ease-out; }
@keyframes rowin { from { background: color-mix(in srgb, var(--accent) 28%, transparent); transform: translateX(-8px); opacity: .4; } }
.item[data-pending="1"] { opacity: .6; }
.item[data-err="1"] { box-shadow: inset 3px 0 0 var(--bad); }
.item .tail { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- hoja inferior y diálogos ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: rgba(4, 8, 18, .62); animation: fade .16s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; margin: 0 auto; max-width: 680px; max-height: 92dvh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line-2); border-bottom: 0; border-radius: 10px 10px 0 0;
  padding: 8px var(--gutter) calc(20px + env(safe-area-inset-bottom, 0px)); animation: rise .2s ease-out; display: flex; flex-direction: column; gap: 14px;
}
.sheet .grip { width: 44px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 4px auto 2px; flex: none; }
.sheet h2 { font-size: 22px; font-weight: 700; }
.sheet .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sheet .actions .btn { flex: 1; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toasts { position: fixed; left: 0; right: 0; z-index: 80; bottom: calc(var(--tab-h) + 90px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 var(--gutter); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 560px; width: 100%; padding: 10px 10px 10px 14px; border-radius: var(--r-1); background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow); animation: rise .2s ease-out; }
.toast[data-k="bad"] { background: var(--bad); color: var(--bg); }
.toast[data-k="ok"] { background: var(--ok); color: var(--bg); }
.toast .btn { min-height: 36px; padding: 0 12px; font-size: 14px; background: transparent; border-color: currentColor; color: inherit; margin-left: auto; }

/* ---------- teclado hexadecimal (Programar) ---------- */
.macbox { display: flex; flex-direction: column; gap: 10px; }
.macfield { font-family: var(--font-mono); font-weight: 600; font-size: clamp(22px, 7.2vw, 32px); letter-spacing: .04em; text-align: center; min-height: 68px; }
.macfield::placeholder { color: var(--line-2); }
.keypad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.keypad button { min-height: 54px; border-radius: var(--r-1); border: 1px solid var(--line-2); background: var(--surface-2); font-family: var(--font-mono); font-size: 20px; font-weight: 600; }
.keypad button:active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.keypad button.wide { grid-column: span 2; font-family: var(--font-ui); font-size: 15px; letter-spacing: .04em; text-transform: uppercase; }
.keypad button.alpha { background: color-mix(in srgb, var(--accent) 9%, var(--surface-2)); }

/* ---------- tarjeta con ranuras R1/R2/R3 ---------- */
.card-t { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); overflow: hidden; }
.card-t > header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.card-t .num { font-family: var(--font-mono); font-size: 22px; font-weight: 600; letter-spacing: .02em; }
.slot { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); min-height: 52px; }
.slot:last-child { border-bottom: 0; }
.slot .nm { font-family: var(--font-mono); font-size: 14px; overflow-wrap: anywhere; }
.slot .mc { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.slot[data-empty="1"] .nm { color: var(--faint); font-family: var(--font-ui); font-style: italic; }

/* ---------- escritorio (monitor) ---------- */
.desk { min-height: 100vh; display: flex; flex-direction: column; }
.desk-top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.desk-nav { display: flex; gap: 2px; margin-left: 12px; }
.desk-nav a, .desk-nav button { min-height: 44px; padding: 0 14px; border: 0; background: transparent; color: var(--muted); font-weight: 700; letter-spacing: .05em; text-transform: uppercase; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; border-bottom: 3px solid transparent; }
.desk-nav [aria-current="page"], .desk-nav [aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.desk-main { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; max-width: 1500px; width: 100%; margin: 0 auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { padding: 12px 14px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-1); display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--line-2); }
.kpi[data-k="ok"]::before { background: var(--ok); }
.kpi[data-k="warn"]::before { background: var(--warn); }
.kpi[data-k="bad"]::before { background: var(--bad); }
.kpi[data-k="info"]::before { background: var(--info); }
.kpi .v { font-family: var(--font-mono); font-size: 34px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.tools-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tools-row .input { min-height: 44px; width: auto; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 500; padding: 9px 12px; border-bottom: 1px solid var(--line-2); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
table.grid td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid td.mono { font-size: 13px; white-space: nowrap; }
table.grid td.act { text-align: right; white-space: nowrap; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.feed { display: flex; flex-direction: column; max-height: 520px; overflow: auto; }
.feed li { list-style: none; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.feed { padding: 0; margin: 0; }
.feed time { font-family: var(--font-mono); font-size: 11px; color: var(--faint); padding-top: 2px; }
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 18, .62); }
.modal > .box { width: min(480px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-2); padding: 18px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
@media (max-width: 1000px) { .two { grid-template-columns: minmax(0, 1fr); } .desk-top, .desk-main { padding-left: 16px; padding-right: 16px; } }

@media (max-width: 1500px) { .hide-md { display: none; } }
.desk-top { flex-wrap: nowrap; }
.desk-top .brand { flex: none; }
@media (max-width: 1100px) { .desk-top { flex-wrap: wrap; } }

/* hoja inferior en móvil, diálogo centrado en escritorio */
@media (min-width: 900px) {
  .sheet { inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: min(540px, 92vw); max-height: 88vh; border: 1px solid var(--line-2); border-radius: var(--r-2); animation: fade .16s ease-out; box-shadow: var(--shadow); }
  .sheet .grip { display: none; }
  .toasts { bottom: 24px; }
}

/* ---------- movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .visor .frame::after { animation: none; top: 50%; }
}
@media (max-width: 360px) {
  :root { --gutter: 12px; }
  .brand-sub:not(button) { display: none; }
  .counters .n { font-size: 24px; }
}
@media (min-width: 700px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* ---------- consultar: ficha de tarjeta ---------- */
.app.app-wide { max-width: 1280px; }
.app-wide .tabbar { max-width: 1280px; }
.app > main.consulta { display: flex; flex-direction: column; gap: var(--gap); }
.cons-side { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.consulta .visor { transition: max-height .28s ease, min-height .28s ease; }

/* móvil: con resultado, cámara + buscador quedan fijos arriba (franja escaneable) y la ficha se desplaza debajo,
   así se puede consultar la siguiente tarjeta sin bajar a "Nueva consulta" */
@media (max-width: 899.98px) {
  .consulta[data-has="1"] .cons-side { position: sticky; top: 0; z-index: 20; margin: -12px calc(var(--gutter) * -1) 0; padding: calc(8px + env(safe-area-inset-top, 0px)) var(--gutter) 8px; gap: 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .consulta[data-has="1"] .visor { aspect-ratio: auto; height: clamp(110px, 17dvh, 150px); min-height: 110px; max-height: 150px; }
  .consulta[data-has="1"] .visor .frame { inset: 10% 16%; }
  .consulta[data-has="1"] .visor .frame i { width: 18px; height: 18px; }
  .consulta[data-has="1"] .visor .tools { flex-direction: row; top: 6px; right: 6px; }
  .consulta[data-has="1"] .visor .status { min-height: 0; top: 6px; left: 6px; max-width: calc(100% - 112px); }
  .consulta[data-has="1"] #formBuscar .btn, .consulta[data-has="1"] #formBuscar .input { min-height: 44px; }
}
@media (min-width: 900px) {
  .app > main.consulta { display: grid; flex-direction: unset; grid-template-columns: 340px minmax(0, 1fr); gap: 24px; align-items: start; }
  .cons-side { position: sticky; top: calc(var(--bar-h) + 12px); }
  .consulta .visor.compact { max-height: none; min-height: 0; }
}

.fichahead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.fh-num { min-width: 0; flex: 1 1 200px; }
.fh-num .silk { margin-bottom: 4px; }
.fichahead .num { font-family: var(--font-mono); font-size: clamp(56px, 19vw, 104px); font-weight: 600; letter-spacing: .01em; line-height: .88; font-variant-numeric: slashed-zero; }
.fh-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; }
.fh-meta .hint { min-height: 18px; }

.fichagrid { display: grid; gap: var(--gap); }
@media (min-width: 900px) { .fichagrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .fichagrid.solo { grid-template-columns: minmax(0, 420px); } }

.pcbf { container-type: inline-size; --tc: var(--line-2); border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); overflow: hidden; box-shadow: inset 4px 0 0 var(--tc); }
.pcbf[data-t="R1"] { --tc: var(--r1); }
.pcbf[data-t="R2"] { --tc: var(--r2); }
.pcbf[data-t="R3"] { --tc: var(--r3); }
.pcbf[data-hit="1"] { border-color: var(--accent); }
.pcbf[data-empty="1"] { border-style: dashed; box-shadow: none; }
.pcbf > header { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; padding: 10px 12px 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.pcbf[data-empty="1"] > header { border-bottom: 0; }
.pcbf .nm { flex: 1 1 160px; font-family: var(--font-mono); font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.macwrap { padding: 12px 12px 0 16px; }
.dt-l, .pcbf dt { font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.macline { display: flex; align-items: center; justify-content: space-between; gap: 6px 10px; margin-top: 2px; }
.macline .btn { padding: 0; width: 44px; flex: none; }
.macval { flex: 1 1 auto; font-size: clamp(16px, 6.4cqi, 24px); font-weight: 600; letter-spacing: .02em; white-space: nowrap; color: var(--text); user-select: all; }
.pcbf dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px 14px; margin: 0; padding: 12px 12px 14px 16px; }
.pcbf dd { margin: 2px 0 0; font-family: var(--font-mono); font-size: 18px; font-weight: 500; overflow-wrap: anywhere; }
.pcbf .soft { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-ui); font-size: 14px; font-weight: 600; color: var(--warn); }
.pcbf .macwrap .soft { font-size: 15px; min-height: 36px; }
.pcbf .soft .svg-i { width: 15px; height: 15px; }
.pcbf-nota { margin: 0; padding: 10px 12px 12px 16px; display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--muted); border-top: 1px dashed var(--line); }
.pcbf-nota .svg-i { margin-top: 2px; color: var(--r3); }

.fichaacts { display: flex; gap: 8px; flex-wrap: wrap; }
.fichaacts .btn { flex: 1 1 140px; }
.fichaacts .act-main { flex: 2 1 180px; }
@media (max-width: 899.98px) {
  .fichaacts { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 6px); z-index: 20; padding: 12px 0 6px; background: linear-gradient(to top, var(--bg) 72%, transparent); }
  .fichaacts .btn { flex-basis: 0; }
}
@media (min-width: 900px) { .fichaacts .btn { flex: 0 0 auto; } }

.ficha-in { animation: fichain .24s ease-out; }
@keyframes fichain { from { opacity: 0; transform: translateY(8px); } }
.skel-ficha { display: flex; flex-direction: column; gap: var(--gap); }
.sk { border-radius: var(--r-2); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; border: 1px solid var(--line); }
.sk-num { height: 84px; width: 62%; }
.sk-card { height: 132px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel { padding: 18px; text-align: center; color: var(--muted); }

/* ---------- hoja de lotes ---------- */
.lotes-intro { font-size: 15px; }
.lote-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface-2); overflow: hidden; }
.lote { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 12px; padding: 12px 12px 12px 14px; border-bottom: 1px solid var(--line); }
.lote:last-child { border-bottom: 0; }
.lote[data-activo="1"] { box-shadow: inset 4px 0 0 var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface-2)); }
.lote-nom { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 19px; font-weight: 700; }
.lote .t2 { font-size: 13px; color: var(--muted); margin-top: 2px; }
.lote-acc { display: flex; flex-wrap: wrap; gap: 8px; }
.lote-auth { border-color: var(--accent); }

/* ---------- versión visible ---------- */
.verpie { margin: 14px 0 0; text-align: center; font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.verpie b { color: var(--accent-text); font-weight: 600; text-transform: none; }
