:root {
  --fondo: #f4f5f7;
  --superficie: #ffffff;
  --superficie-2: #eceef2;
  --texto: #15181d;
  --texto-suave: #5b6270;
  --borde: #d5d9e0;
  --acento: #1f6feb;
  --acento-texto: #ffffff;
  --ok: #1a7f37;
  --pronto: #b7791f;
  --caducado: #c62828;
  --sin-stock: #8a909b;
  --peligro: #c62828;
  --radio: 14px;
  --sombra: 0 2px 10px rgb(0 0 0 / 0.12);
  color-scheme: light;
}

/* La bodega va siempre en oscuro (pantalla encendida todo el día, brillo bajo). */
:root.oscuro {
  --fondo: #0e1116;
  --superficie: #1a1f27;
  --superficie-2: #252c37;
  --texto: #eef1f5;
  --texto-suave: #9aa3b2;
  --borde: #313a47;
  --acento: #3d8bfd;
  --ok: #3fb950;
  --pronto: #e3a73b;
  --caducado: #f2564f;
  --sin-stock: #6b7380;
  --sombra: 0 2px 14px rgb(0 0 0 / 0.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.claro) {
    --fondo: #0e1116;
    --superficie: #1a1f27;
    --superficie-2: #252c37;
    --texto: #eef1f5;
    --texto-suave: #9aa3b2;
    --borde: #313a47;
    --acento: #3d8bfd;
    --ok: #3fb950;
    --pronto: #e3a73b;
    --caducado: #f2564f;
    --sin-stock: #6b7380;
    --sombra: 0 2px 14px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { cursor: default; opacity: 0.45; }

input, select {
  font: inherit;
  color: var(--texto);
  background: var(--superficie-2);
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 12px;
  width: 100%;
}

.estado-caducado { --color-estado: var(--caducado); }
.estado-pronto { --color-estado: var(--pronto); }
.estado-ok { --color-estado: var(--ok); }
.estado-vacio { --color-estado: var(--sin-stock); }
.estado-sin-fecha { --color-estado: var(--borde); }

/* ---------- Aviso de conexión ---------- */
.sin-conexion {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  display: none;
  padding: 18px 16px;
  background: var(--peligro);
  color: #fff;
  font-weight: 800;
  font-size: 1.4rem;
  text-align: center;
}
body.desconectado .sin-conexion { display: block; }
body.desconectado .requiere-conexion { pointer-events: none; opacity: 0.35; }

/* ---------- Aviso con deshacer ---------- */
.aviso {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translate(-50%, 160%);
  transition: transform 0.18s ease-out;
  z-index: 40;
  width: min(680px, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 18px;
  border-radius: var(--radio);
  background: var(--texto);
  color: var(--fondo);
  box-shadow: var(--sombra);
  overflow: hidden;
}
.aviso.visible { transform: translate(-50%, 0); }
.aviso.error { background: var(--peligro); color: #fff; }
.aviso-texto { flex: 1; font-weight: 600; font-size: 1.1rem; }
.aviso-deshacer {
  flex: none;
  padding: 14px 22px;
  border-radius: 10px;
  background: var(--acento);
  color: var(--acento-texto);
  font-weight: 800;
  font-size: 1.1rem;
}
.aviso-barra {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  background: var(--acento);
  width: 100%;
  transform-origin: left;
}

/* ---------- Hojas (diálogos) ---------- */
dialog.hoja {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: min(640px, 100%);
  max-height: 92vh;
  border-radius: 20px 20px 0 0;
  background: var(--superficie);
  color: var(--texto);
  box-shadow: var(--sombra);
}
@media (min-height: 700px) and (min-width: 700px) {
  dialog.hoja { margin: auto; border-radius: 20px; }
}
dialog.hoja::backdrop { background: rgb(0 0 0 / 0.55); }
.hoja-contenido { padding: 20px 20px max(20px, env(safe-area-inset-bottom)); display: grid; gap: 18px; }
.hoja h2 { margin: 0; font-size: 1.5rem; }
.hoja-sub { margin: -12px 0 0; color: var(--texto-suave); }
.hoja-grupo { display: grid; gap: 8px; }
.hoja-etiqueta { font-size: 0.9rem; font-weight: 700; color: var(--texto-suave); text-transform: uppercase; letter-spacing: 0.04em; }
.opciones { display: flex; flex-wrap: wrap; gap: 8px; }
.opcion {
  min-height: 56px;
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--superficie-2);
  border: 2px solid transparent;
  font-weight: 650;
  font-size: 1.1rem;
}
.opcion[aria-pressed="true"] { border-color: var(--acento); background: color-mix(in srgb, var(--acento) 18%, var(--superficie-2)); }
.opcion small { display: block; font-weight: 500; color: var(--texto-suave); font-size: 0.85rem; }
.contador { display: flex; align-items: center; gap: 12px; }
.contador button {
  width: 64px; height: 64px;
  border-radius: 14px;
  background: var(--superficie-2);
  font-size: 2rem; font-weight: 700;
}
.contador output { min-width: 3ch; text-align: center; font-size: 2.2rem; font-weight: 800; }
.hoja-acciones { display: flex; gap: 10px; }
.boton {
  flex: 1;
  min-height: 60px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--superficie-2);
  font-weight: 700;
  font-size: 1.1rem;
}
.boton.principal { background: var(--acento); color: var(--acento-texto); }
.boton.peligro { background: var(--peligro); color: #fff; }
