/* ============================================================
   §10 — NUTRICIÓN v2 (Workstream C)
   Sheet "Agregar comida" con 3 accesos [Buscar | Escanear | IA],
   autocomplete local con favoritos/recientes, escáner de barcode
   (overlay fullscreen) y edición/duplicado de comidas.
   Usa los tokens de app.css; tap targets ≥ 44px.
   ============================================================ */

/* ---------- accesos [Buscar | Escanear | IA] ---------- */
.nx-modes {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 16px 0 12px;
}
.nx-mode {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 46px; padding: 10px 6px;
  border: 1px solid var(--hair-strong); border-radius: var(--r-sm);
  background: var(--card-2); color: var(--text-2);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease),
              border-color .18s var(--ease), transform .12s var(--ease);
}
.nx-mode .ic { width: 18px; height: 18px; }
.nx-mode:active { transform: scale(.97); }
.nx-mode.active {
  background: var(--accent-soft); border-color: transparent; color: var(--accent);
}

/* ---------- panel Buscar (autocomplete local) ---------- */
.nx-panel { margin-bottom: 4px; }
#nx-q {
  width: 100%; min-height: 46px; padding: 11px 14px;
  border: 1px solid var(--hair-strong); border-radius: var(--r-sm);
  background: var(--card-2); color: var(--text);
  font: inherit; font-size: 16px; /* 16px evita el zoom de iOS */
  outline: none; -webkit-appearance: none; appearance: none;
}
#nx-q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.nx-results {
  margin-top: 8px; max-height: 264px; overflow-y: auto;
  border-radius: var(--r-sm); background: var(--card-2);
  border: 1px solid var(--hair);
}
.nx-results:empty { display: none; }
.nx-res-head {
  padding: 10px 14px 4px; font-size: 12px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-3);
}
.nx-empty { padding: 16px 14px; font-size: 14px; color: var(--text-2); }

.nx-food-row {
  display: flex; align-items: center; gap: 4px;
  min-height: 52px; padding: 6px 10px 6px 2px; cursor: pointer;
  border-bottom: 1px solid var(--hair);
  transition: background .15s var(--ease);
}
.nx-food-row:last-child { border-bottom: none; }
.nx-food-row:active { background: var(--accent-soft); }
.nx-food-main { flex: 1; min-width: 0; }
.nx-food-name {
  font-size: 15px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nx-food-sub {
  font-size: 12.5px; color: var(--text-3); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nx-food-kcal { flex: none; font-size: 15px; font-weight: 700; color: var(--text); }
.nx-food-kcal span { font-size: 11px; font-weight: 500; color: var(--text-3); }
.nx-tag {
  display: inline-block; margin-left: 6px; padding: 2px 7px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: var(--r-pill); vertical-align: 2px;
}

/* estrella de favorito — tap target completo de 44px */
.nx-star {
  flex: none; width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border: none; background: none; cursor: pointer;
  color: var(--text-3); border-radius: 50%;
  transition: color .15s var(--ease), transform .12s var(--ease);
}
.nx-star:active { transform: scale(.9); }
.nx-star.on { color: var(--orange); }

/* porción del alimento elegido */
.nx-portion {
  margin-top: 10px; padding: 12px;
  background: var(--card-2); border: 1px solid var(--hair);
  border-radius: var(--r-sm);
}
.nx-portion-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.nx-portion-row { display: flex; align-items: center; gap: 8px; }
.nx-portion-row input {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--hair-strong); border-radius: var(--r-sm);
  background: var(--card); color: var(--text); font: inherit; font-size: 16px;
  outline: none;
}
.nx-portion-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.nx-portion-unit { flex: none; font-size: 14px; font-weight: 600; color: var(--text-2); }
.nx-portion-pv { margin-top: 8px; font-size: 13.5px; color: var(--text-2); }

/* ---------- vista día: editar / copiar de ayer ---------- */
.nx-meal-row { cursor: pointer; }
.nx-meal-row:active { background: var(--accent-soft); }
.nx-copy-row { display: flex; justify-content: center; margin: 18px 0 8px; }
.nx-copy-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
}
.nx-dup { margin-bottom: 10px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }

/* ============================================================
   Escáner de código de barras — overlay fullscreen propio
   (encima del sheet-host z-60, debajo del toast z-80).
   El overlay es oscuro por diseño (cámara): colores fijos.
   ============================================================ */
.scan-overlay {
  position: fixed; inset: 0; z-index: 75;
  background: #000; display: flex; flex-direction: column;
  animation: scan-in .22s var(--ease);
}
@keyframes scan-in { from { opacity: 0; } to { opacity: 1; } }
.scan-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
/* máscara con ventana de mira (el box-shadow gigante oscurece alrededor) */
.scan-shade { position: absolute; inset: 0; pointer-events: none; }
.scan-window {
  position: absolute; left: 50%; top: 42%;
  width: min(78vw, 340px); height: 152px;
  transform: translate(-50%, -50%);
  border-radius: 14px; border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 0 0 200vmax rgba(0,0,0,.55);
  overflow: hidden;
}
.scan-line {
  position: absolute; left: 8%; right: 8%; height: 2px;
  background: #FF453A; border-radius: 2px; opacity: .9;
  animation: scan-sweep 1.6s ease-in-out infinite alternate;
}
@keyframes scan-sweep { from { top: 12%; } to { top: 86%; } }
@media (prefers-reduced-motion: reduce) {
  .scan-line { animation: none; top: 50%; }
}

.scan-top {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 10px) 10px 10px;
}
.scan-close {
  flex: none; width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border: none; border-radius: 50%; cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.scan-close:active { transform: scale(.94); }
.scan-title {
  flex: 1; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  color: #fff; font-size: 15px; font-weight: 700;
  text-shadow: 0 1px 6px rgba(0,0,0,.5);
}
.scan-top-spacer { flex: none; width: 44px; }

.scan-hint {
  position: absolute; left: 16px; right: 16px; top: calc(42% + 96px);
  z-index: 2; text-align: center;
  color: rgba(255,255,255,.92); font-size: 14px; font-weight: 500;
  text-shadow: 0 1px 6px rgba(0,0,0,.6);
}
.scan-actions {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 22px);
  z-index: 2; display: flex; justify-content: center;
}
.scan-manual-btn {
  min-height: 44px; padding: 11px 20px;
  border: none; border-radius: var(--r-pill); cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff;
  font: inherit; font-size: 14.5px; font-weight: 600;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.scan-manual-btn:active { transform: scale(.97); }

/* panel inferior del escáner (porción / no encontrado / captura) */
.scan-panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  background: var(--card); color: var(--text);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  box-shadow: var(--shadow-lg);
  animation: scanp-up .26s var(--ease);
  max-height: 76vh; overflow-y: auto;
}
@keyframes scanp-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 900px) {
  .scan-panel { left: 50%; right: auto; width: 440px; transform: translateX(-50%); border-radius: var(--r-lg); bottom: 32px; }
  @keyframes scanp-up { from { transform: translate(-50%, 24px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
}

.scanp-head { margin-bottom: 12px; }
.scanp-name { font-size: 17px; font-weight: 700; }
.scanp-brand { font-size: 13.5px; color: var(--text-2); margin-top: 2px; }
.scanp-per100 { font-size: 13.5px; color: var(--text-2); margin-top: 6px; }
.scanp-unit { color: var(--text-3); font-size: 12px; }

.scanp-portion { display: grid; gap: 7px; }
.scanp-portion > label { font-size: 13px; font-weight: 600; color: var(--text-2); padding-left: 4px; }
.scanp-grow { display: grid; gap: 8px; }
.scanp-grow input {
  min-height: 46px; padding: 11px 14px; width: 100%;
  border: 1px solid var(--hair-strong); border-radius: var(--r-sm);
  background: var(--card-2); color: var(--text); font: inherit; font-size: 16px;
  outline: none;
}
.scanp-grow input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.scanp-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.scanp-chips .chip { min-height: 40px; }
.scanp-preview { margin-top: 10px; font-size: 14px; color: var(--text-2); min-height: 18px; }

.scanp-actions { display: flex; gap: 10px; margin-top: 16px; }
.scanp-actions .btn-ghost, .scanp-actions .btn-primary { flex: 1; min-height: 48px; }

.scanp-form { display: grid; gap: 12px; }
.scanp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
