/* ============================================================
   Recepción — lenguaje visual iOS: system font, fondo grouped,
   listas inset, chrome translúcido (nav + tab bar), tint azul,
   colores semánticos del sistema, dark mode automático.
   ============================================================ */
:root {
  color-scheme: light dark;
  --fondo: #f2f2f7; --sup: #ffffff; --sup-2: #f2f2f7; --relleno: rgba(120,120,128,.12); --relleno-2: rgba(120,120,128,.20);
  --hair: rgba(60,60,67,.18); --hair-fuerte: rgba(60,60,67,.29);
  --txt: #000000; --txt-2: rgba(60,60,67,.6); --txt-3: rgba(60,60,67,.3);
  --tint: #007aff; --tint-tinte: rgba(0,122,255,.12); --tint-txt: #ffffff;
  --ok: #34c759; --ok-tinte: rgba(52,199,89,.14);
  --falta: #ff3b30; --falta-tinte: rgba(255,59,48,.12);
  --sobra: #ff9500; --sobra-tinte: rgba(255,149,0,.14);
  --presion: #d1d1d6;
  --cromo: rgba(249,249,249,.78); --cromo-borde: rgba(0,0,0,.12);
  --scrim: rgba(0,0,0,.4);
  --sombra-sheet: 0 -2px 30px rgba(0,0,0,.18);
  --r: 12px; --r-grande: 16px; --r-btn: 12px;
  --tab-h: 50px; --nav-h: 44px;
  --fuente: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --spring: cubic-bezier(.2,.9,.25,1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #000000; --sup: #1c1c1e; --sup-2: #2c2c2e; --relleno: rgba(120,120,128,.24); --relleno-2: rgba(120,120,128,.36);
    --hair: rgba(84,84,88,.6); --hair-fuerte: rgba(84,84,88,.65);
    --txt: #ffffff; --txt-2: rgba(235,235,245,.6); --txt-3: rgba(235,235,245,.3);
    --tint: #0a84ff; --tint-tinte: rgba(10,132,255,.18);
    --ok: #30d158; --ok-tinte: rgba(48,209,88,.18);
    --falta: #ff453a; --falta-tinte: rgba(255,69,58,.18);
    --sobra: #ff9f0a; --sobra-tinte: rgba(255,159,10,.18);
    --presion: #3a3a3c;
    --cromo: rgba(29,29,31,.72); --cromo-borde: rgba(255,255,255,.14);
    --scrim: rgba(0,0,0,.55);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--fuente); font-size: 17px; line-height: 1.3; letter-spacing: -0.01em;
  background: var(--fondo); color: var(--txt); overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 34px; letter-spacing: -0.025em; line-height: 1.1; }
h2 { font-size: 22px; letter-spacing: -0.02em; line-height: 1.15; }
h3 { font-size: 17px; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.mute { color: var(--txt-2); } .mute-3 { color: var(--txt-3); }
.small { font-size: 13px; letter-spacing: 0; }
.oculto { display: none !important; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--tint-tinte); }

/* ---- layout ---- */
#app { min-height: 100%; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); }
.vista { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px 24px; }
.cabecera { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 20px 0 14px; }
.cabecera .sub { color: var(--txt-2); font-size: 15px; margin-top: 4px; font-weight: 500; }
.seccion { margin-top: 28px; }
.seccion-titulo { display: flex; align-items: baseline; justify-content: space-between; padding: 0 16px; margin-bottom: 8px; }
.seccion-titulo h2 { font-size: 13px; font-weight: 500; color: var(--txt-2); text-transform: uppercase; letter-spacing: .02em; }
.seccion-titulo .link { font-size: 15px; color: var(--tint); background: none; }
.seccion-titulo .link:active { opacity: .5; }

/* nav bar compacta (aparece al scrollear el large title) */
#navc {
  position: fixed; inset-inline: 0; top: 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 17px;
  background: var(--cromo); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 .5px 0 var(--cromo-borde); transform: translateY(-100%); opacity: 0; transition: transform 220ms var(--spring), opacity 180ms ease; pointer-events: none;
}
#navc.visible { transform: none; opacity: 1; }

/* nav bar de vista (detalle) */
.barra-top {
  position: sticky; top: 0; z-index: 25; margin: 0 -16px 12px; padding: calc(env(safe-area-inset-top) + 4px) 8px 4px; min-height: var(--nav-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px;
  background: var(--cromo); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 .5px 0 var(--cromo-borde);
}
.barra-top h2 { grid-column: 2; font-size: 17px; font-weight: 600; text-align: center; letter-spacing: -0.01em; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-top > :first-child { grid-column: 1; justify-self: start; }
.barra-top > :last-child:not(h2) { grid-column: 3; justify-self: end; }
.barra-top .sub { display: none; }
.btn-nav { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px; color: var(--tint); font-size: 17px; border-radius: 8px; }
.btn-nav svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn-nav:active { opacity: .4; }

/* ---- tab bar ---- */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20; max-width: 100%;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--cromo); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -.5px 0 var(--cromo-borde);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10px; font-weight: 500; letter-spacing: 0; color: rgba(120,120,128,.9); }
.tabs a svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: transform 200ms var(--spring); }
.tabs a:active svg { transform: scale(.88); }
.tabs a.activo { color: var(--tint); }
.tabs a.activo svg { fill: var(--tint); fill-opacity: .18; stroke-width: 2; }

/* ---- botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 0 20px; border-radius: var(--r-btn); font-weight: 600; font-size: 17px;
  background: var(--relleno); color: var(--tint); user-select: none;
  transition: transform 120ms ease-out, opacity 120ms ease-out, background 120ms ease-out;
}
.btn:active { transform: scale(.96); opacity: .8; }
.btn-primario { background: var(--tint); color: var(--tint-txt); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-falta { background: var(--falta-tinte); color: var(--falta); }
.btn-borde { background: var(--relleno); color: var(--tint); }
.btn-bloque { width: 100%; }
.btn-chico { min-height: 34px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn-icono { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
.btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn[disabled] { opacity: .35; pointer-events: none; }
.fila-btns { display: flex; gap: 10px; margin-top: 16px; }
.fila-btns .btn { flex: 1; }
.fila-btns .btn-icono { flex: 0 0 50px; width: 50px; height: 50px; border-radius: var(--r-btn); }
.link { color: var(--tint); font-size: 15px; background: none; }
.link:active { opacity: .5; }
.btn-texto { color: var(--tint); font-weight: 400; background: none; min-height: 44px; }
.btn-texto:active { opacity: .4; }

/* ---- listas inset agrupadas ---- */
.card { background: var(--sup); border-radius: var(--r); }
.lista { display: flex; flex-direction: column; background: var(--sup); border-radius: var(--r); overflow: hidden; }
.item {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 11px 16px; width: 100%; text-align: left;
  background: var(--sup); color: inherit; min-height: 56px;
  transition: background 80ms ease-out;
}
.item::after { content: ""; position: absolute; left: 16px; right: 0; bottom: 0; height: .5px; background: var(--hair); }
.item:has(.avatar)::after { left: 70px; }
.item:last-child::after { display: none; }
.item:active { background: var(--presion); transition: none; }
.item .cuerpo { flex: 1; min-width: 0; }
.item .titulo { font-weight: 500; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .detalle { font-size: 14px; color: var(--txt-2); margin-top: 1px; letter-spacing: 0; }
.item .der { text-align: right; flex-shrink: 0; }
.item .der .num { font-weight: 500; }
a.item::before, .item[data-prod]::before, .item[data-id]::before { /* chevron de navegación */
  content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--txt-3); border-bottom: 2px solid var(--txt-3); transform: translateY(-50%) rotate(-45deg);
}
a.item, .item[data-prod], .item[data-id] { padding-right: 36px; }
.item .btn-chico { position: relative; z-index: 1; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 600; font-size: 15px; letter-spacing: 0; background: var(--relleno); color: var(--txt-2);
}
.avatar.ok { background: var(--ok-tinte); color: var(--ok); }
.avatar.falta { background: var(--falta-tinte); color: var(--falta); }
.avatar.sobra { background: var(--sobra-tinte); color: var(--sobra); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 7px; font-size: 12px; font-weight: 600; letter-spacing: 0; background: var(--relleno); color: var(--txt-2); white-space: nowrap; }
.chip.ok { background: var(--ok-tinte); color: var(--ok); }
.chip.falta { background: var(--falta-tinte); color: var(--falta); }
.chip.sobra { background: var(--sobra-tinte); color: var(--sobra); }
.chip.info { background: var(--tint-tinte); color: var(--tint); }
.vacio { text-align: center; padding: 36px 20px; color: var(--txt-2); }
.vacio h2 { color: var(--txt); margin-bottom: 6px; font-size: 20px; }
.vacio p { margin: 0 0 18px; font-size: 15px; }
.vacio .fila-btns { flex-direction: column; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 14px 14px 12px; background: var(--sup); border-radius: var(--r); }
.stat .v { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--txt-2); margin-top: 6px; letter-spacing: 0; font-weight: 500; }
.stat.falta .v { color: var(--falta); }
.stat.ok .v { color: var(--ok); }

/* ---- forms ---- */
.campo { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.campo label { font-size: 13px; font-weight: 500; color: var(--txt-2); padding-left: 4px; letter-spacing: 0; text-transform: uppercase; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 10px; border: 0;
  background: var(--relleno); outline: none; appearance: none; -webkit-appearance: none;
  transition: box-shadow 120ms ease-out;
}
.input:focus { box-shadow: 0 0 0 3px var(--tint-tinte); }
.input::placeholder { color: var(--txt-3); }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 9l4-4 4 4M8 15l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; padding-right: 36px; }
textarea.input { min-height: 88px; resize: vertical; }
.campo-fila { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--tint); margin: 0; }
.buscador { position: relative; margin-bottom: 12px; }
.buscador .input { padding-left: 36px; min-height: 38px; padding-block: 7px; font-size: 17px; }
.buscador svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; stroke: var(--txt-3); fill: none; stroke-width: 2.2; }
.buscador .btn-scan { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 36px; min-height: 34px; background: none; color: var(--tint); }

/* stepper (UIStepper) */
.stepper { display: inline-flex; align-items: center; border-radius: 9px; background: var(--relleno); overflow: hidden; }
.stepper button { width: 42px; height: 38px; font-size: 22px; font-weight: 400; color: var(--txt); display: grid; place-items: center; }
.stepper button:active { background: var(--relleno-2); }
.stepper input { width: 56px; height: 38px; text-align: center; border: 0; outline: none; font-weight: 600; font-size: 18px; background: transparent; font-variant-numeric: tabular-nums; }
.stepper input:focus { background: var(--sup); }

/* ---- control de entrega ---- */
.progreso { height: 4px; background: var(--relleno); border-radius: 2px; overflow: hidden; margin: 8px 0 4px; }
.progreso > div { height: 100%; background: var(--tint); border-radius: 2px; transition: width 300ms var(--spring); }
.ctl-item { padding: 14px 16px; background: var(--sup); border-radius: var(--r); box-shadow: inset 0 0 0 1px transparent; transition: box-shadow 200ms ease; }
.ctl-item.ok { box-shadow: inset 0 0 0 1.5px var(--ok); }
.ctl-item.falta { box-shadow: inset 0 0 0 1.5px var(--falta); }
.ctl-item.sobra { box-shadow: inset 0 0 0 1.5px var(--sobra); }
.ctl-item + .ctl-item { margin-top: 10px; }
#c-lista { background: none; border-radius: 0; overflow: visible; gap: 10px; }
.ctl-item .enc { display: flex; align-items: flex-start; gap: 10px; }
.ctl-item .enc .cuerpo { flex: 1; min-width: 0; }
.ctl-item .nombre { font-weight: 600; font-size: 17px; }
.ctl-item .pedido { font-size: 14px; color: var(--txt-2); letter-spacing: 0; }
.ctl-item .acciones { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.ctl-item .btn-todo { min-height: 38px; }
.ctl-item .nota-btn { font-size: 14px; color: var(--tint); margin-top: 10px; letter-spacing: 0; }
.ctl-item .nota-btn:active { opacity: .5; }
.ctl-item .nota { font-size: 14px; color: var(--sobra); margin-top: 8px; letter-spacing: 0; }
.resumen-lista { display: flex; flex-direction: column; margin: 12px 0; background: var(--relleno); border-radius: var(--r); padding: 0 14px; }
.resumen-lista .fila { display: flex; justify-content: space-between; gap: 10px; padding: 11px 0; border-bottom: .5px solid var(--hair); font-size: 15px; }
.resumen-lista .fila:last-child { border-bottom: 0; }
.pie-fijo {
  position: fixed; inset-inline: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 15;
  background: var(--cromo); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -.5px 0 var(--cromo-borde); padding: 10px 16px;
}
body.sin-tabs .pie-fijo { bottom: 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
body.sin-tabs #app { padding-bottom: 0; }
.pie-fijo .interno { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.pie-fijo .btn { flex: 1; }
.con-pie { padding-bottom: 96px; }

/* ---- sheet (modal iOS) ---- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; animation: fade 220ms ease-out; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 41; background: var(--sup);
  border-radius: 14px 14px 0 0; padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain; max-width: 640px; margin: 0 auto;
  box-shadow: var(--sombra-sheet); animation: subir 380ms var(--spring); will-change: transform; touch-action: pan-y;
}
.sheet.arrastrando { animation: none; transition: none; }
.sheet .asa { width: 36px; height: 5px; border-radius: 3px; background: var(--hair-fuerte); margin: 4px auto 14px; }
.sheet h2 { margin-bottom: 14px; font-size: 20px; }
.sheet .lista { background: var(--sup-2); }
.sheet .item { background: var(--sup-2); }
.sheet .item:active { background: var(--presion); }
@media (prefers-color-scheme: dark) { .sheet { background: var(--sup); } .sheet .lista, .sheet .item { background: var(--sup-2); } }
@keyframes subir { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes bajar-toast { from { transform: translate(-50%, -140%); opacity: 0 } to { transform: translate(-50%, 0); opacity: 1 } }

/* toast (notificación arriba, estilo iOS) */
.toast {
  position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--cromo); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  color: var(--txt); padding: 11px 18px; border-radius: 999px; box-shadow: 0 6px 24px rgba(0,0,0,.18), 0 0 0 .5px var(--cromo-borde);
  font-size: 15px; font-weight: 500; z-index: 60; animation: bajar-toast 420ms var(--spring); max-width: 90vw; text-align: center; letter-spacing: 0;
}

/* scanner */
.scanner video { width: 100%; border-radius: var(--r); background: #000; aspect-ratio: 3/4; object-fit: cover; }
.scanner .marco { position: relative; }
.scanner .marco::after { content: ""; position: absolute; inset: 30% 12%; border: 2px solid #fff; border-radius: 10px; opacity: .85; }

/* tabla detalle */
.tabla { width: 100%; border-collapse: collapse; font-size: 15px; }
.tabla th { text-align: left; font-size: 12px; color: var(--txt-2); font-weight: 500; padding: 10px 0 6px; text-transform: uppercase; letter-spacing: .02em; }
.tabla td { padding: 11px 0; border-top: .5px solid var(--hair); vertical-align: top; }
.tabla td.n, .tabla th.n { text-align: right; white-space: nowrap; }
.aviso { padding: 12px 14px; border-radius: var(--r); font-size: 15px; font-weight: 500; }
.aviso.falta { background: var(--falta-tinte); color: var(--falta); }
.aviso.ok { background: var(--ok-tinte); color: var(--ok); }
.aviso.info { background: var(--tint-tinte); color: var(--tint); }
.aviso.sobra { background: var(--sobra-tinte); color: var(--sobra); }

/* filtros (capsulas iOS) */
.filtros { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filtros::-webkit-scrollbar { display: none; }
.filtros .chip { padding: 7px 13px; font-size: 14px; border-radius: 999px; font-weight: 500; transition: transform 120ms ease-out; }
.filtros .chip:active { transform: scale(.95); }
.filtros .chip.info { background: var(--tint); color: #fff; }

/* accesibilidad y preferencias */
@media (prefers-reduced-motion: reduce) {
  .sheet, .scrim, .toast, #navc { animation: none !important; transition: opacity 150ms ease !important; }
  .btn:active, .tabs a:active svg { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .tabs, .barra-top, #navc, .pie-fijo, .toast { background: var(--sup); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (min-width: 700px) {
  .tabs { max-width: 640px; margin: 0 auto; border-radius: 18px 18px 0 0; }
}
.item.sin-chev::before { display: none; } .item.sin-chev { padding-right: 16px; }
.btn-nav svg circle { fill: currentColor; }
