/* Nitsu Vision PWA — Design System
 * Fuente única: tokens/nitsu-tokens.json → vars CSS (mantener en sync, make tokens-check)
 * Principios: densidad Linear, claridad Stripe, canvas Runway. Sin gradiente purple, sin emoji.
 */
:root {
  --bg: #0f1419;
  --bg-soft: #f2f5f7;
  --bg-card: #ffffff;
  --bg-elevated: #1d2630;
  --text: #0f1419;
  --text-muted: #5a6a7a;
  --text-inverse: #ffffff;
  --text-subtle: #9fb0be;
  --border: #d6dde3;
  --border-strong: #1d2630;
  --accent: #1a7a42;
  --accent-soft: #e8f5ec;
  --accent-border: #bfe0c8;
  --warn: #b45309;
  --warn-soft: #fff7e6;
  --warn-border: #f2d9a0;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --overlay: rgba(15, 20, 25, 0.72);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-xl: 22px;
  --radius-pill: 999px;

  --shadow-card: 0 6px 18px rgba(15, 20, 25, 0.08);
  --shadow-phone: 0 18px 40px rgba(15, 20, 25, 0.14);

  --motion-fast: 150ms;
  --motion-base: 220ms;
  --spring: cubic-bezier(0.22, 1, 0.36, 1);

  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --space-xs: 6px;
  --space-sm: 10px;
  --space-md: 16px;
  --space-lg: 24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg-soft);
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- Phone shell (en desktop se ve como celu; en móvil ocupa pantalla) ---- */
.phone {
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  background: var(--bg-card);
  box-shadow: var(--shadow-phone);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
@media (min-width: 480px) {
  body { padding: 24px 0; }
  .phone { min-height: 844px; border: 1px solid var(--border); border-radius: var(--radius-xl); }
}

/* ---- Header ---- */
.top {
  background: var(--bg);
  color: #fff;
  padding: 14px 16px 12px;
}
.topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; }
.pair {
  font-size: 11px; background: var(--bg-elevated); color: #cfe6d8;
  border: 1px solid #2a3643; padding: 5px 10px; border-radius: var(--radius-pill);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.dot.off { background: var(--warn); }
.dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: 0.35; transform: scale(0.8);} }
.top h1 { font-size: 19px; font-weight: 850; line-height: 1.2; margin-top: 10px; }
.top p { color: #b8c2cc; font-size: 12px; line-height: 1.45; margin-top: 4px; }
.link {
  background: none; border: none; color: var(--accent); font-size: 11px;
  font-weight: 800; cursor: pointer; font-family: var(--sans); padding: 4px;
}
.link.install { color: #8fe3ad; border: 1px solid #2a5a3c; padding: 5px 10px; border-radius: var(--radius-pill); }

/* ---- Pasos 1-2 ---- */
.steps { display: flex; gap: 8px; padding: 12px 16px 0; }
.step {
  flex: 1; border: 1px solid var(--border); background: var(--bg-soft);
  border-radius: var(--radius-lg); padding: 10px; cursor: pointer;
  transition: transform var(--motion-fast) var(--spring), background var(--motion-fast);
}
.step:active { transform: scale(0.98); }
.step.active { background: var(--bg); color: #fff; border-color: var(--bg); }
.snum {
  width: 22px; height: 22px; border-radius: 50%; background: var(--bg); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; margin-bottom: 6px;
}
.step.active .snum { background: #fff; color: var(--bg); }
.step b { display: block; font-size: 12px; line-height: 1.2; }
.step span { font-size: 11px; color: var(--text-muted); line-height: 1.3; }
.step.active span { color: #c9d6e2; }

/* ---- Avisos ---- */
.notice {
  margin: 10px 16px 0; border-radius: var(--radius-md); padding: 9px 11px;
  font-size: 11px; line-height: 1.4;
}
.notice.priv { background: var(--warn-soft); border: 1px solid var(--warn-border); color: #5a4310; }
.notice.ok { background: var(--accent-soft); border: 1px solid var(--accent-border); color: #144a28; }
.notice.offline { background: var(--danger-soft); border: 1px solid #fecaca; color: var(--danger); font-weight: 600; }
.notice.install { background: var(--bg); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notice.install button {
  background: #fff; color: var(--bg); border: none; font-family: var(--sans);
  font-size: 11px; font-weight: 800; padding: 7px 12px; border-radius: var(--radius-pill); cursor: pointer;
}

/* ---- Guardar chips ---- */
.save { margin: 10px 16px 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.save b { font-size: 11px; color: var(--text); }
.chip {
  padding: 7px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--bg-card); font-size: 11px; font-weight: 600; color: var(--text);
  font-family: var(--sans); cursor: pointer; transition: all var(--motion-fast) var(--spring);
}
.chip:active { transform: scale(0.96); }
.chip.on { background: var(--bg); color: #fff; border-color: var(--bg); }
.hint { margin: 6px 16px 0; font-size: 11px; color: var(--text-muted); line-height: 1.4; text-align: center; }

/* ---- Ghost pallet 3D ---- */
.ghost {
  margin: 10px 16px 0; border: 1.5px dashed var(--accent-border); background: var(--accent-soft);
  border-radius: var(--radius-lg); padding: 10px; display: flex; align-items: center; gap: 10px;
  position: relative; overflow: hidden;
}
.ghost::after { /* línea de escaneo sutil */
  content: ""; position: absolute; left: 0; right: 0; top: -20%;
  height: 30%; background: linear-gradient(180deg, transparent, rgba(26,122,66,0.12), transparent);
  animation: scan 2.8s linear infinite;
}
@keyframes scan { 0% { top: -30%; } 100% { top: 130%; } }
.ghostbox {
  width: 92px; height: 62px; border-radius: var(--radius-sm); background: var(--bg-card);
  border: 1px solid var(--accent-border); display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 800; font-size: 11px; flex-shrink: 0; font-family: var(--mono);
  box-shadow: 0 2px 8px rgba(15,20,25,0.06);
}
.ghost p { margin: 0; font-size: 11px; line-height: 1.4; color: #1a4d2e; }
.ghost p strong { color: #0f7a3a; }

/* ---- Cámara ---- */
.camera {
  margin: 10px 16px 0; height: 282px; background: #0a0e12; border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center; color: var(--text-subtle);
  position: relative; overflow: hidden; border: 1px solid #1c242e;
}
.camera video { width: 100%; height: 100%; object-fit: cover; }
.camera .ph { font-size: 11px; text-align: center; padding: 12px; line-height: 1.5; }
.frame {
  position: absolute; inset: 14px; border: 1.5px dashed rgba(255,255,255,0.28);
  border-radius: var(--radius-md); pointer-events: none;
}
.scanline { /* barrido al medir */
  position: absolute; left: 14px; right: 14px; height: 2px; background: var(--accent);
  box-shadow: 0 0 12px var(--accent); top: 20%; animation: sweep 900ms ease-in-out infinite alternate;
  pointer-events: none; opacity: 0; transition: opacity var(--motion-fast);
}
.scanline.on { opacity: 1; }
@keyframes sweep { from { top: 20%; } to { top: 78%; } }

/* ---- CTA / shutter ---- */
.cta {
  margin: 12px 16px 0; background: var(--bg); color: #fff; border: 1px solid var(--bg);
  border-radius: var(--radius-lg); padding: 14px; text-align: center; font-weight: 850;
  font-size: 15px; letter-spacing: 0.01em; cursor: pointer; font-family: var(--sans);
  transition: transform var(--motion-fast) var(--spring), background var(--motion-fast), box-shadow var(--motion-fast);
  box-shadow: 0 4px 14px rgba(15,20,25,0.18);
}
.cta small { display: block; margin-top: 4px; font-weight: 600; font-size: 11px; color: #b8c2cc; }
.cta:active { transform: scale(0.98); box-shadow: none; }
.cta.stop { background: var(--danger); border-color: var(--danger); }
.cta.cabina-on { background: var(--danger); border-color: var(--danger); }
.cta:disabled { opacity: 0.55; cursor: wait; }

/* ---- Resultado ---- */
.result {
  margin: 10px 16px 0; border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; background: var(--bg-soft); animation: rise var(--motion-base) var(--spring);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none;} }
.rhead { padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; background: var(--bg-card); border-bottom: 1px solid var(--border); }
.rhead b { font-size: 12px; }
.conf {
  font-size: 11px; font-weight: 800; padding: 5px 8px; border-radius: var(--radius-pill);
  border: 1px solid var(--accent-border); background: var(--accent-soft); color: #144a28;
}
.conf.med { border-color: var(--warn-border); background: var(--warn-soft); color: #5a4310; }
.conf.low { border-color: #fecaca; background: var(--danger-soft); color: var(--danger); }
.rbody { padding: 12px; }
.big {
  font-family: var(--mono); font-size: 30px; font-weight: 800; color: var(--text);
  letter-spacing: -0.02em; line-height: 1.1;
}
.big small { font-size: 14px; color: var(--text-muted); font-weight: 600; }
.dims { font-family: var(--mono); font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.mode-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: 10px; font-weight: 800; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--accent-border);
  padding: 4px 8px; border-radius: var(--radius-pill);
}
.mode-badge.edge { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.rsub { font-size: 11px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }

/* Barra de confianza */
.confbar { margin-top: 10px; }
.confbar .clabel { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; color: var(--text); }
.confbar .track { height: 8px; background: #e2e8ee; border-radius: var(--radius-pill); overflow: hidden; margin-top: 6px; }
.confbar .fill { height: 100%; border-radius: var(--radius-pill); transition: width 600ms var(--spring); }

/* Skeleton mientras mide */
.skeleton { padding: 12px; }
.skel-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, #e2e8ee 25%, #eef1f3 50%, #e2e8ee 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin-bottom: 8px; }
.skel-line.big { height: 28px; width: 55%; }
.skel-line.w70 { width: 70%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---- Cola / offline ---- */
.queue {
  margin: 10px 16px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-card);
}
.queue .qtext { font-size: 11px; color: var(--text); line-height: 1.4; }
.queue .qtext strong { color: var(--accent); }
.btn-small {
  padding: 6px 12px; border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--bg-card); font-size: 11px; font-weight: 700; color: var(--text);
  font-family: var(--sans); cursor: pointer; transition: background var(--motion-fast);
}
.btn-small:active { background: var(--bg-soft); }

/* ---- Cabina tenue ---- */
.cabina-status {
  margin: 10px 16px 0; border: 1px solid var(--accent-border); background: var(--accent-soft);
  border-radius: var(--radius-lg); padding: 12px; display: flex; align-items: center; gap: 10px;
}
.cabina-status .dot { width: 12px; height: 12px; }
.cabina-status b { font-size: 13px; color: #144a28; display: block; }
.cabina-status span { font-size: 11px; color: #1a4d2e; }
.cabina-alert {
  margin: 10px 16px 0; border: 1px solid #fecaca; background: var(--danger-soft);
  border-radius: var(--radius-lg); padding: 12px; animation: shake 400ms var(--spring);
}
.cabina-alert b { color: var(--danger); font-size: 13px; }
.cabina-alert span { font-size: 11px; color: #7f1d1d; display: block; margin-top: 2px; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px);} 75% { transform: translateX(4px);} }

/* ---- Preview capturada ---- */
.preview { margin: 10px 16px 0; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); width: 100%; height: 200px; object-fit: cover; }

/* ---- Progreso de escaneo (verificación de que está midiendo) ---- */
.scan-progress {
  margin: 8px 16px 0; display: flex; align-items: center; justify-content: center;
  gap: 4px; font-size: 10px; font-weight: 700; color: var(--text-muted); flex-wrap: wrap;
}
.scan-progress .sp { padding: 4px 8px; border-radius: var(--radius-pill); background: var(--bg-soft); border: 1px solid var(--border); }
.scan-progress .sp.active { background: var(--bg); color: #fff; border-color: var(--bg); animation: pulse 1.2s infinite; }
.scan-progress .sp.done { background: var(--accent-soft); color: #144a28; border-color: var(--accent-border); }
.scan-progress i { color: var(--text-subtle); font-style: normal; }
.camoff-row { margin: 8px 16px 0; display: flex; justify-content: center; }
.camoff { color: var(--danger); border-color: #fecaca; }

/* ---- Mis archivos y permisos ---- */
.storage {
  margin: 14px 16px 0; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-card);
}
.storage summary {
  padding: 10px 12px; font-size: 12px; font-weight: 800; cursor: pointer;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.storage summary::-webkit-details-marker { display: none; }
.storage summary::before { content: "▸"; transition: transform var(--motion-base); color: var(--text-muted); }
.storage[open] summary::before { transform: rotate(90deg); }
.st-body { padding: 0 12px 12px; display: grid; gap: 8px; }
.st-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; }
.st-row span { color: var(--text-muted); }
.st-row b { font-weight: 700; }
.usage { height: 6px; background: #e2e8ee; border-radius: var(--radius-pill); overflow: hidden; }
.usage-fill { height: 100%; width: 0; background: var(--accent); border-radius: var(--radius-pill); transition: width 500ms var(--spring); }
.usage-fill.high { background: var(--warn); }
.st-where { text-align: left; margin: 0; font-size: 10px; line-height: 1.5; }
.st-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 140px; overflow: auto; }
.st-list li {
  display: flex; align-items: center; gap: 8px; font-size: 11px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 8px;
}
.st-list li span { flex: 1; color: var(--text); }
.st-list li b { font-family: var(--mono); font-weight: 600; }
.st-list li em { font-style: normal; font-weight: 800; font-size: 10px; }
.st-list li em.ok { color: var(--accent); }
.st-list li em.pend { color: var(--warn); }
.st-list li.empty { justify-content: center; color: var(--text-muted); background: none; border-style: dashed; }
.st-actions { display: flex; gap: 8px; }
.btn-small.danger { color: var(--danger); border-color: #fecaca; }
.mono { font-family: var(--mono); }

/* ---- Footer ---- */
.foot { margin: auto 16px 16px; padding-top: 12px; text-align: center; font-size: 10px; color: var(--text-muted); line-height: 1.5; }

/* ---- Toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(16px);
  background: var(--bg); color: #fff; font-size: 12px; font-weight: 600; padding: 10px 16px;
  border-radius: var(--radius-pill); opacity: 0; pointer-events: none;
  transition: opacity var(--motion-base), transform var(--motion-base) var(--spring);
  z-index: 50; box-shadow: 0 8px 24px rgba(15,20,25,0.3);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- A11y ---- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
