:root {
  --accent: #1F63E0; --accent-soft: #E8F0FE; --accent-line: #A9C4F5;
  --ink: #172033; --muted: #64748B; --line: #E2E8F0; --bg: #F4F6FA; --surface: #FFFFFF;
  --danger: #B42318; --danger-soft: #FEF3F2; --ok: #027A48; --ok-soft: #ECFDF3; --warn: #B54708; --warn-soft: #FFFAEB;
  --radius: 12px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }
.ok-text { color: var(--ok); } .danger-text { color: var(--danger); } .warn-text { color: var(--warn); }
.right { text-align: right; } .nowrap { white-space: nowrap; }

/* Ingreso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px calc(24px + var(--safe-bottom)); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.brand strong { display: block; font-size: 17px; } .brand small { color: var(--muted); }
.brand-mark { width: 44px; height: 44px; object-fit: contain; flex: none; }
.login-users { display: grid; gap: 8px; }
.user-btn { padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-align: left; font-weight: 600; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 14px 0 18px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots i.on { background: var(--accent); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-pad button { padding: 16px 0; font-size: 22px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.pin-pad button:active { background: var(--accent-soft); }

/* Barra, menú y contenido */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-top)) 8px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; font-size: 20px; }
.icon-btn:active { background: var(--accent-soft); }
.drawer { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(300px, 84vw); background: var(--surface); transform: translateX(-102%);
  transition: transform .2s ease; overflow-y: auto; padding: calc(14px + var(--safe-top)) 10px calc(14px + var(--safe-bottom)); box-shadow: 0 0 30px rgba(0,0,0,.15); }
.drawer.open { transform: none; }
.drawer-head { display: flex; gap: 10px; align-items: center; padding: 6px 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.drawer-head small { display: block; color: var(--muted); }
.nav-item { display: flex; width: 100%; gap: 12px; align-items: center; padding: 12px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; font-weight: 600; text-decoration: none; color: var(--ink); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item.danger { color: var(--danger); margin-top: 8px; }
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(15,23,42,.35); opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
main { padding: 12px 12px calc(28px + var(--safe-bottom)); max-width: 820px; margin: 0 auto; outline: none; }

/* Bloques */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin-bottom: 8px; }
.card h3 { font-size: 14px; margin: 10px 0 6px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi .label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.kpi .value { font-size: 19px; font-weight: 700; margin-top: 4px; }
.kpi .delta { font-size: 12px; margin-top: 2px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 12px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.seg button.on { background: var(--accent); color: #fff; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 12px; color: var(--muted); }
.row.tap { cursor: pointer; }
.row.loss { background: var(--danger-soft); } .row.gain { background: var(--ok-soft); }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.pill.danger { background: var(--danger-soft); color: var(--danger); } .pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.alert { border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.danger { background: var(--danger-soft); color: var(--danger); } .alert.info { background: var(--accent-soft); color: var(--accent); }
.chart-box { position: relative; height: 210px; }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; }

/* Formularios */
.field { display: block; margin-bottom: 11px; }
.field > span { display: block; font-size: 12px; font-weight: 700; margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid #CBD5E1; border-radius: 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-line); border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.check input { width: auto; }
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.btn-row .btn { flex: 1; }
.link { border: 0; background: transparent; color: var(--accent); font-weight: 700; padding: 8px 0; }
.qty-input { width: 108px; text-align: right; padding: 9px 10px; }
.search { margin-bottom: 10px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 calc(6px + var(--safe-bottom)); }

/* Aviso y hoja inferior */
.toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translate(-50%, 140%); background: var(--ink); color: #fff; padding: 11px 16px;
  border-radius: 10px; max-width: 92vw; z-index: 60; transition: transform .25s, opacity .25s, visibility .25s; font-size: 14px;
  opacity: 0; visibility: hidden; pointer-events: none; }  /* oculto del todo: antes asomaba como una pastilla vacía */
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; } .toast.error { background: var(--danger); }
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + var(--safe-bottom)); }
.sheet h2 { font-size: 18px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 11px; color: var(--muted); }
td.num, th.num { text-align: right; white-space: nowrap; }
.bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; display: flex; }
.bar > i { display: block; height: 100%; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.bio-btn { margin: 4px 0 14px; font-size: 16px; padding: 14px 16px; }
/* Buscadores de productos y proveedores */
.picker { position: relative; }
.picker-input { width: 100%; }
.picker.invalid .picker-input { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.picker-list { margin-top: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); max-height: 260px; overflow-y: auto; }
.picker-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 11px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; font-weight: 600; }
.picker-item:last-child { border-bottom: 0; }
.picker-item:active { background: var(--accent-soft, #e8f0fd); }
.picker-item small { font-weight: 400; color: var(--muted); font-size: 12px; }
.picker-none { padding: 11px 12px; color: var(--muted); font-size: 13px; }
