:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e8ec;
  --brand: #0f172a;
  --accent: #10b981;
  --accent-ink: #ffffff;
  --christian: #2563eb;
  --christian-soft: #e8effd;
  --anthony: #f59e0b;
  --anthony-soft: #fef3e0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 720px; margin: 0 auto; padding-bottom: 84px; }

/* ---------- Pantallas de entrada (quién soy + PIN) ---------- */
.gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.gate .logo {
  width: 84px; height: 84px; border-radius: 24px;
  background: linear-gradient(135deg, #0f172a, #10b981);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 26px; letter-spacing: -0.5px;
  margin-bottom: 18px;
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.28);
}
.gate h1 { font-size: 22px; margin: 0 0 6px; }
.gate p { color: var(--muted); margin: 0 0 26px; font-size: 15px; }

.person-pick { display: flex; gap: 12px; width: 100%; max-width: 420px; }
.person-btn {
  flex: 1; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); padding: 22px 12px; cursor: pointer;
  font-family: var(--font); font-size: 17px; font-weight: 700; color: var(--ink);
  transition: transform .06s ease, border-color .15s ease, box-shadow .15s ease;
}
.person-btn:active { transform: scale(0.97); }
.person-btn .dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; margin-right: 8px; vertical-align: -1px; }
.person-btn.christian.selected { border-color: var(--christian); box-shadow: 0 0 0 4px var(--christian-soft); }
.person-btn.anthony.selected { border-color: var(--anthony); box-shadow: 0 0 0 4px var(--anthony-soft); }
.dot.christian { background: var(--christian); }
.dot.anthony { background: var(--anthony); }

.pin-dots { display: flex; gap: 14px; margin: 8px 0 28px; }
.pin-dots span {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid #cbd5e1; background: transparent;
  transition: all .12s ease;
}
.pin-dots span.on { background: var(--brand); border-color: var(--brand); transform: scale(1.1); }

.pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; justify-content: center; }
.key {
  height: 72px; border-radius: 50%; border: none; background: var(--card);
  font-family: var(--font); font-size: 26px; font-weight: 600; color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  transition: transform .05s ease;
}
.key:active { transform: scale(0.9); background: #eef2f7; }
.key.alt { font-size: 15px; color: var(--muted); }
.key.done { background: var(--accent); color: #fff; font-size: 22px; }

.gate .err { color: var(--danger); min-height: 20px; font-size: 14px; margin-top: 16px; font-weight: 600; }
.gate .hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.link { color: var(--brand); font-weight: 600; cursor: pointer; background: none; border: none; font-size: 14px; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar .title { font-weight: 800; font-size: 18px; letter-spacing: -0.3px; }
.topbar .who {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,0.12); border: none; color: #fff;
  padding: 7px 12px; border-radius: 999px; font-family: var(--font); font-size: 13px; font-weight: 700; cursor: pointer;
}
.topbar .who .dot { width: 9px; height: 9px; border-radius: 50%; }

/* ---------- Resumen balance ---------- */
.balance-wrap { padding: 14px 16px 4px; }
.balance-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; gap: 12px; align-items: stretch;
}
.balance-side { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.balance-side .nm { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.balance-side .nm .dot { width: 10px; height: 10px; border-radius: 50%; }
.balance-side .big { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.balance-side .sub { color: var(--muted); font-size: 12.5px; }
.balance-divider { width: 1px; background: var(--line); }
.lead-badge {
  margin-top: 8px; font-size: 13px; font-weight: 700; padding: 7px 12px; border-radius: 10px;
  background: var(--christian-soft); color: #1d4ed8;
}
.lead-badge.anthony { background: var(--anthony-soft); color: #b45309; }

/* ---------- Pestañas de sección ---------- */
.section-tabs {
  display: flex; gap: 8px; padding: 12px 16px 4px; overflow-x: auto; scrollbar-width: none;
}
.section-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1; min-width: 84px; text-align: center; padding: 10px 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  font-family: var(--font); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Contenido ---------- */
.content { padding: 14px 16px; }
.content h2.section-title { font-size: 15px; margin: 6px 0 12px; color: var(--ink); }

.empty {
  text-align: center; color: var(--muted); padding: 48px 20px; font-size: 15px;
}
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* ---------- Tarjetas de producto ---------- */
.product-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .product-grid { grid-template-columns: 1fr 1fr; } }

.product-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; position: relative;
}
.product-card .row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.product-card .nm { font-weight: 800; font-size: 16px; line-height: 1.2; }
.product-card .cat { font-size: 12px; color: var(--muted); margin-top: 2px; }
.product-card .price { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 2px; }

.stock-badge {
  font-size: 13px; font-weight: 800; padding: 4px 10px; border-radius: 8px; white-space: nowrap;
  background: #eef2f7; color: var(--ink);
}
.stock-badge.zero { background: var(--anthony-soft); color: #b45309; }
.stock-badge.neg { background: var(--danger-soft); color: var(--danger); }

.turn-pill {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 12px;
  font-size: 13.5px; font-weight: 700;
}
.turn-pill .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.turn-pill.christian { background: var(--christian-soft); color: #1d4ed8; }
.turn-pill.anthony { background: var(--anthony-soft); color: #b45309; }
.turn-pill .tag { font-weight: 600; color: var(--muted); font-size: 12px; }

.product-actions { display: flex; gap: 8px; }
.product-actions .btn { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: 12px; padding: 12px 14px; cursor: pointer;
  font-family: var(--font); font-size: 15px; font-weight: 700; transition: transform .05s ease, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.brand { background: var(--brand); color: #fff; }
.btn.ghost { background: #eef2f7; color: var(--ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom) + 8px);
  z-index: 25; width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 30px; font-weight: 400; cursor: pointer;
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.4);
  display: flex; align-items: center; justify-content: center; transition: transform .05s ease;
}
.fab:active { transform: scale(0.92); }

/* ---------- Historial ---------- */
.mov { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; }
.mov .ic { width: 40px; height: 40px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 19px; }
.mov.sale .ic { background: var(--christian-soft); }
.mov.restock .ic { background: #e6f7f0; }
.mov .body { flex: 1; min-width: 0; }
.mov .t { font-weight: 700; font-size: 14.5px; }
.mov .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.mov .r { text-align: right; flex: none; }
.mov .amt { font-weight: 800; font-size: 14.5px; }
.mov .qty { font-size: 12.5px; color: var(--muted); }
.mov .who { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; margin-top: 4px; }
.mov .who.christian { background: var(--christian-soft); color: #1d4ed8; }
.mov .who.anthony { background: var(--anthony-soft); color: #b45309; }
.mov .who .dot { width: 7px; height: 7px; border-radius: 50%; }
.mov .del { border: none; background: none; color: #cbd5e1; cursor: pointer; font-size: 18px; padding: 6px; }
.mov .del:hover { color: var(--danger); }

/* ---------- Resumen ---------- */
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.stat-card .h { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .nm { width: 90px; font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.bar-row .nm .dot { width: 9px; height: 9px; border-radius: 50%; }
.bar-track { flex: 1; height: 10px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.bar-row .val { width: 92px; text-align: right; font-weight: 800; font-size: 13.5px; }

.breakdown { margin-top: 4px; }
.breakdown .item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.breakdown .item:last-child { border-bottom: none; }
.breakdown .item .l { display: flex; align-items: center; gap: 8px; min-width: 0; }
.breakdown .item .l .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.breakdown .item .l span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown .item .v { font-weight: 700; white-space: nowrap; }

/* ---------- Ajustes ---------- */
.setting-row { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.setting-row .h { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 12px; }
.field { width: 100%; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 12px 13px; border-radius: 12px; border: 1.5px solid var(--line);
  font-family: var(--font); font-size: 15px; color: var(--ink); background: #fff;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.stepper { display: flex; align-items: center; gap: 0; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; width: fit-content; }
.stepper button { width: 46px; height: 46px; border: none; background: #eef2f7; font-size: 22px; cursor: pointer; color: var(--ink); font-weight: 700; }
.stepper .v { width: 56px; text-align: center; font-weight: 800; font-size: 18px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch .t { font-weight: 700; font-size: 14.5px; }
.toggle { position: relative; width: 50px; height: 30px; border-radius: 999px; background: #cbd5e1; border: none; cursor: pointer; transition: background .15s; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(20px); }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  animation: up .22s cubic-bezier(.2,.9,.3,1);
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: #cbd5e1; margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 19px; }
.sheet .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.sheet .field { margin-bottom: 12px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet .actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 100; opacity: 0; pointer-events: none; transition: all .25s ease; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--accent); }
.toast.err { background: var(--danger); }

/* ---------- Navegación inferior ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .nb {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 7px; border: none; background: none; cursor: pointer;
  font-family: var(--font); font-size: 11px; font-weight: 700; color: var(--muted);
}
.bottomnav .nb .ico { font-size: 21px; line-height: 1; }
.bottomnav .nb.active { color: var(--brand); }

/* ---------- Spinner ---------- */
.loading { text-align: center; padding: 60px 20px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid #e6e8ec; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 14px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #eef2f7; color: var(--muted); }
