:root {
  --crema: #FFF3E0;
  --papel: #FFFCF6;
  --linea: #EAD7BC;
  --tinta: #3A2518;
  --suave: #6B5444;
  --terracota: #B8431B;
  --terracota-osc: #8F3112;
  --salvia: #3F6E3B;
  --ambar-bg: #FFE19A;  --ambar-tx: #6A4300;  --ambar: #E39A12;
  --rojo-bg: #F8CBC0;   --rojo-tx: #8A1A08;   --rojo: #C62E14;
  --radio: 18px;
  --tabs-h: 76px;
  --sombra: 0 2px 0 rgba(58,37,24,.08), 0 8px 20px rgba(58,37,24,.07);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 18px; }
body {
  margin: 0; background: var(--crema); color: var(--tinta);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.35; min-height: 100dvh;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* ---------- cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--crema);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 2px solid var(--linea);
}
.top h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; }
.quien { display: flex; background: #F6E3C6; border-radius: 999px; padding: 4px; }
.quien button {
  border: 0; background: transparent; padding: 10px 14px; min-height: 44px; border-radius: 999px;
  font-weight: 700; color: var(--suave);
}
.quien button.on { background: var(--terracota); color: #fff; }

main { padding: 14px 16px calc(var(--tabs-h) + 130px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

/* ---------- pestañas ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--papel); border-top: 2px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; height: var(--tabs-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: .85rem; font-weight: 700; color: var(--suave);
}
.tabs .ico { font-size: 1.6rem; line-height: 1; filter: grayscale(.8); opacity: .75; }
.tabs button.on { color: var(--terracota); }
.tabs button.on .ico { filter: none; opacity: 1; }

/* ---------- botones ---------- */
.btn {
  border: 2px solid var(--linea); background: var(--papel); border-radius: 16px; min-height: 58px;
  padding: 0 18px; font-weight: 800; font-size: 1.05rem; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn.primario { background: var(--terracota); border-color: var(--terracota-osc); color: #fff; box-shadow: 0 3px 0 var(--terracota-osc); }
.btn.salvia { background: var(--salvia); border-color: #2D5429; color: #fff; box-shadow: 0 3px 0 #2D5429; }
.btn.grande { min-height: 66px; font-size: 1.2rem; }
.btn:disabled { opacity: .55; }

/* ---------- barra de acción fija (Inventario) ---------- */
.accion-fija {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); z-index: 9;
  padding: 10px 16px; background: linear-gradient(to top, var(--crema) 70%, rgba(255,243,224,0));
}
.accion-fija .btn { max-width: 608px; margin: 0 auto; display: flex; }

/* ---------- inventario ---------- */
.aviso {
  border-radius: var(--radio); padding: 12px 14px; font-weight: 700; margin-bottom: 14px;
  background: var(--ambar-bg); color: var(--ambar-tx); border: 2px solid var(--ambar);
}
.aviso.rojo { background: var(--rojo-bg); color: var(--rojo-tx); border-color: var(--rojo); }
.cat { margin: 20px 0 8px; font-size: 1.05rem; font-weight: 800; color: var(--suave); text-transform: uppercase; letter-spacing: .05em; display: flex; gap: 8px; align-items: center; }
.cat:first-child { margin-top: 4px; }
.card {
  background: var(--papel); border: 2px solid var(--linea); border-left-width: 8px; border-radius: var(--radio);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--sombra);
}
.card.ambar { border-left-color: var(--ambar); }
.card.rojo { border-left-color: var(--rojo); }
.card.ok { border-left-color: var(--salvia); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.nombre { font-size: 1.3rem; font-weight: 800; overflow-wrap: anywhere; }
.tam { color: var(--suave); font-weight: 600; margin-top: 2px; }
.cuenta { text-align: right; flex: none; }
.cuenta b { display: block; font-size: 2.6rem; line-height: 1; font-weight: 800; }
.cuenta span { color: var(--suave); font-size: .85rem; font-weight: 600; }
.badge { display: inline-block; margin-top: 8px; padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 800; background: #EEF3E8; color: var(--salvia); }
.badge.ambar { background: var(--ambar-bg); color: var(--ambar-tx); }
.badge.rojo { background: var(--rojo-bg); color: var(--rojo-tx); }
.card-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.card-btns .btn { min-height: 56px; }
.vacio { text-align: center; padding: 48px 12px; color: var(--suave); }
.vacio .grande { font-size: 3.5rem; }
.vacio p { margin-top: 8px; font-size: 1.1rem; }

/* ---------- hojas (formularios) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(58,37,24,.5); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--papel);
  border-radius: 26px 26px 0 0; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); max-width: 680px; margin: 0 auto;
  animation: sube .18s ease-out;
}
@keyframes sube { from { transform: translateY(40px); opacity: .6; } }
.sheet::before { content: ""; display: block; width: 46px; height: 5px; border-radius: 3px; background: var(--linea); margin: 0 auto 12px; }
.sheet h2 { font-size: 1.45rem; font-weight: 800; margin-bottom: 4px; }
.sheet .sub { color: var(--suave); margin-bottom: 12px; font-weight: 600; }
label.campo { display: block; font-weight: 800; margin: 16px 0 6px; }
input[type=text], input[type=password], input[type=number], input[type=date], textarea {
  width: 100%; min-height: 58px; border: 2px solid var(--linea); border-radius: 14px; padding: 12px 14px;
  font: inherit; font-size: 1.1rem; background: #fff; color: var(--tinta);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus { outline: 3px solid var(--terracota); outline-offset: 1px; border-color: var(--terracota); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  min-height: 52px; padding: 0 16px; border-radius: 14px; border: 2px solid var(--linea); background: #fff; font-weight: 700;
}
.chips button.on { background: var(--terracota); border-color: var(--terracota-osc); color: #fff; }
.stepper { display: grid; grid-template-columns: 76px 1fr 76px; gap: 10px; align-items: center; }
.stepper button { height: 72px; border-radius: 18px; border: 2px solid var(--linea); background: #fff; font-size: 2.2rem; font-weight: 800; }
.stepper button:active { background: #F6E3C6; }
.stepper output { text-align: center; font-size: 3rem; font-weight: 800; }
.sheet .btn { margin-top: 18px; }
.sheet .cancelar { background: none; border-color: transparent; color: var(--suave); min-height: 50px; margin-top: 6px; }
.err { color: var(--rojo-tx); font-weight: 700; min-height: 1.2em; margin-top: 6px; }

/* ---------- sugerencias ---------- */
.sug-form { margin-bottom: 16px; }
.sug-form .btn { margin-top: 12px; }
.sug {
  background: var(--papel); border: 2px solid var(--linea); border-radius: 22px; padding: 16px; margin-bottom: 16px; box-shadow: var(--sombra);
}
.sug h3 { font-size: 1.3rem; font-weight: 800; line-height: 1.2; }
.sug .tag { display: inline-block; margin: 0 0 8px; padding: 3px 10px; border-radius: 999px; background: var(--ambar-bg); color: var(--ambar-tx); font-size: .85rem; font-weight: 800; }
.comp { padding: 12px 0; border-top: 2px dashed var(--linea); }
.comp:first-of-type { margin-top: 12px; }
.rol { font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--suave); }
.comp .n { font-size: 1.15rem; font-weight: 800; }
.saca { font-size: 1.25rem; font-weight: 800; color: var(--terracota); margin-top: 2px; }
.saca small { display: block; color: var(--suave); font-weight: 600; font-size: .9rem; }
.nota { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: #FDEBD0; font-weight: 600; }
.sug .btn { margin-top: 14px; }

/* ---------- historial ---------- */
.dia { margin: 18px 0 6px; font-weight: 800; color: var(--suave); text-transform: capitalize; }
.dia:first-child { margin-top: 4px; }
.mov { display: flex; gap: 12px; align-items: center; background: var(--papel); border: 2px solid var(--linea); border-radius: 16px; padding: 12px; margin-bottom: 8px; }
.mov .f { flex: none; width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem; font-weight: 800; }
.mov .f.entrada { background: #E3EEDD; color: var(--salvia); }
.mov .f.salida { background: var(--rojo-bg); color: var(--rojo-tx); }
.mov .t { font-weight: 800; overflow-wrap: anywhere; }
.mov .s { color: var(--suave); font-weight: 600; font-size: .9rem; }

/* ---------- login y toast ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--papel); border: 2px solid var(--linea); border-radius: 26px; padding: 26px 22px; width: 100%; max-width: 420px; text-align: center; box-shadow: var(--sombra); }
.login-ico { font-size: 3.6rem; }
.login-card h1 { font-size: 2rem; font-weight: 800; }
.login-card p { color: var(--suave); margin: 8px 0 16px; }
.login-card .err { margin: 6px 0 0; min-height: 1.4em; text-align: left; }
.login-card .btn { margin-top: 10px; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 86px + env(safe-area-inset-bottom)); z-index: 40;
  margin: 0 auto; max-width: 440px; background: var(--tinta); color: #fff; border-radius: 16px; padding: 14px 16px; font-weight: 700;
  text-align: center; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s;
}
.toast.ver { opacity: 1; transform: none; }
.toast.mal { background: var(--rojo-tx); }
.cargando { text-align: center; color: var(--suave); padding: 40px; font-weight: 700; }
