:root{
  --bg:#f4f5f7; --card:#fff; --ink:#1c2430; --muted:#6b7684;
  --brand:#0d6e4f; --brand-d:#0a583f; --line:#e3e7eb;
  --err:#c0392b; --ok:#0d6e4f;
}
*{box-sizing:border-box}
/* El atributo hidden debe ganar SIEMPRE, aunque el elemento tenga display:flex.
   Sin esto, .menu/.scanbox/.cart quedan visibles pese a tener [hidden]. */
[hidden]{display:none!important}
html,body{margin:0;height:100%}
body{
  font:16px/1.4 system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
  background:var(--bg); color:var(--ink);
  padding-bottom:env(safe-area-inset-bottom);
}
h1{font-size:1.4rem;margin:.2rem 0 .6rem}
h2{font-size:1.2rem}
.muted{color:var(--muted)} .small{font-size:.85rem}
.error{color:var(--err);min-height:1.2em;margin:.4rem 0 0}

/* barra superior */
#topbar{
  position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:.6rem;
  padding:.7rem 1rem;background:var(--brand);color:#fff;
  padding-top:calc(.7rem + env(safe-area-inset-top));
}
#topbar strong{flex:0 0 auto}
.pill{margin-left:auto;font-size:.75rem;background:rgba(255,255,255,.2);
  padding:.15rem .5rem;border-radius:1rem}
.pill.ok{background:#12925f} .pill.bad{background:#b23b2e}
.icon{background:none;border:0;color:inherit;font-size:1.3rem;cursor:pointer}

/* vistas y tarjetas */
.view{padding:1rem;max-width:640px;margin:0 auto}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;
  padding:1.2rem;box-shadow:0 1px 3px rgba(0,0,0,.05)}
label{display:block;margin:.6rem 0;font-size:.9rem;color:var(--muted)}
input{width:100%;font-size:1rem;padding:.7rem;margin-top:.25rem;
  border:1px solid var(--line);border-radius:10px;background:#fff;color:var(--ink)}
button{font-size:1rem;padding:.7rem 1rem;border-radius:10px;border:1px solid transparent;cursor:pointer}
button.primary{background:var(--brand);color:#fff;width:100%;margin-top:.6rem}
button.primary:active{background:var(--brand-d)}
button.primary.small{width:auto;margin:0;padding:.5rem .8rem}
button.ghost{background:none;border:1px solid var(--line);width:100%;margin-top:.5rem}
button.ghost.small,button.icon{width:auto;margin:0}

/* toolbar / búsqueda */
.toolbar{position:sticky;top:0;z-index:4;display:flex;gap:.5rem;align-items:center;
  padding:.6rem;background:var(--bg)}
.toolbar input{margin:0}
.segmented{display:flex;gap:.4rem;padding:0 .6rem .4rem}
.segmented button{flex:1;background:#fff;border:1px solid var(--line);font-size:.85rem;padding:.5rem}
.segmented button.active{background:var(--brand);color:#fff;border-color:var(--brand)}

/* listas */
.list{list-style:none;margin:0;padding:0}
.list li{display:flex;align-items:center;gap:.6rem;background:#fff;
  border-bottom:1px solid var(--line);padding:.7rem .8rem}
.list li .name{flex:1;min-width:0}
.list li .name b{display:block;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.list li .stock{font-size:.8rem;color:var(--muted)}
.list li .add{background:var(--brand);color:#fff;border-radius:8px;padding:.35rem .7rem;font-size:.9rem}
.tag{font-size:.72rem;padding:.1rem .45rem;border-radius:1rem;background:#eef1f4;color:var(--muted)}
.tag.recep{background:#e6f3ee;color:var(--ok)}
.tag.count{background:#eaf0fb;color:#2456b8}
.neg{color:var(--err)}

/* carrito */
.cart{position:fixed;left:0;right:0;bottom:0;background:#fff;border-top:2px solid var(--brand);
  max-height:55vh;display:flex;flex-direction:column;box-shadow:0 -4px 12px rgba(0,0,0,.08)}
.cart-head{display:flex;align-items:center;gap:.6rem;padding:.7rem 1rem;font-weight:600}
.cart-head .primary{margin-left:auto}
.cart .list{overflow:auto}

/* menú */
.menu-overlay{position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:9}
.menu{position:fixed;top:0;right:0;bottom:0;width:70%;max-width:300px;background:#fff;
  box-shadow:-4px 0 16px rgba(0,0,0,.15);z-index:10;padding:calc(1rem + env(safe-area-inset-top)) 1rem 1rem;
  display:flex;flex-direction:column;gap:.5rem}
.menu button{background:#fff;border:1px solid var(--line);text-align:left}
.menu-close{color:var(--muted);font-size:.9rem}

/* cámara */
.scanbox{position:fixed;inset:0;background:#000;z-index:20;display:flex;
  flex-direction:column;align-items:center;justify-content:center;gap:1rem}
.scanbox video{width:100%;max-width:520px;border-radius:8px}
.scanbox .ghost{color:#fff;border-color:#fff;width:auto}

/* toast */
.toast{position:fixed;left:50%;bottom:1.2rem;transform:translateX(-50%);z-index:30;
  background:#1c2430;color:#fff;padding:.7rem 1rem;border-radius:10px;font-size:.9rem;
  max-width:90%}
.toast.err{background:var(--err)}

dialog{border:0;border-radius:14px;padding:1.2rem;width:90%;max-width:360px}
dialog h3{margin:.1rem 0 .3rem}
dialog input{font-size:1.4rem;text-align:center}
dialog menu{display:flex;gap:.6rem;padding:0;margin:1rem 0 0}
dialog menu button{flex:1;margin:0}

@media (prefers-color-scheme: dark){
  :root{--bg:#12161c;--card:#1a2129;--ink:#e6eaef;--muted:#93a0ad;--line:#2a333d}
  input,.list li,.segmented button{background:#1a2129}
  .menu,.cart,dialog{background:#1a2129}
}
