:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --card: #ffffff;
  --card2: #f5f6f8;
  --txt: #1a1a1a;
  --muted: #6b6b6b;
  --borde: #e5e5e5;
  --verde: #1a6b3a;
  --verde-claro: #2d9257;
  --rojo: #c8161d;
  --accent: #2d9257;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --azul: #2563eb;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-soft); color: var(--txt);
  padding: env(safe-area-inset-top) 0 90px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

/* ---------- cabecera ---------- */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; position: sticky; top: 0; z-index: 5;
  background: rgba(255,255,255,.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--borde);
}
header h1 { font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
header .sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.hdr-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.back {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--borde);
  background: var(--card); color: var(--verde); font-size: 20px; font-weight: 700;
  flex: 0 0 auto;
}

/* ---------- contenedor ---------- */
main { padding: 14px 16px; max-width: 900px; margin: 0 auto; }
.section-title {
  font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 20px 0 10px;
}

/* ---------- tarjetas KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi {
  background: var(--card); border: 1px solid var(--borde); border-radius: 14px;
  padding: 12px 14px;
}
.kpi .lbl { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.kpi .val { font-size: 22px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; }
.kpi .val.bad { color: var(--bad); }
.kpi .val.warn { color: var(--warn); }
.kpi .val.ok { color: var(--ok); }

/* ---------- buscador y filtros ---------- */
.toolbar { display: flex; gap: 8px; margin: 14px 0 10px; flex-wrap: wrap; }
.toolbar input[type=search], .toolbar input[type=text] { flex: 1 1 180px; }
input, select, textarea {
  font-family: inherit; font-size: 15px; color: var(--txt);
  background: var(--card); border: 1px solid var(--borde); border-radius: 11px;
  padding: 11px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--verde-claro); outline-offset: -1px; }
label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 5px; }
.ayuda { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.3; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- botones ---------- */
button, .btn {
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
  border: 1px solid var(--borde); background: var(--card); color: var(--txt);
  border-radius: 11px; padding: 11px 14px; transition: .12s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active, .btn:active { transform: scale(.97); }
.btn-primary { background: var(--verde); border-color: var(--verde); color: #fff; }
.btn-danger  { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost   { background: transparent; }
.btn-sm { padding: 7px 10px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.chip {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--borde);
  background: var(--card); font-size: 13px; font-weight: 700; cursor: pointer;
}
.chip.on { background: var(--verde); border-color: var(--verde); color: #fff; }

/* ---------- lista de productos ---------- */
.lista { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--card); border: 1px solid var(--borde); border-radius: 14px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.item.bajo { border-color: #f3c2c2; background: #fff8f8; }
.item.cero { border-color: var(--bad); background: #fff1f1; }
.item .info { flex: 1 1 auto; min-width: 0; }
.item .nom { font-size: 15px; font-weight: 700; line-height: 1.25; }
.item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item .stock { text-align: right; flex: 0 0 auto; }
.item .stock .n { font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.item .stock .n.bad { color: var(--bad); }
.item .stock .n.warn { color: var(--warn); }
.item .stock .u { font-size: 11px; color: var(--muted); font-weight: 600; }
.acciones { display: flex; gap: 6px; flex: 0 0 auto; }
.acciones button {
  width: 38px; height: 38px; padding: 0; font-size: 20px; font-weight: 800; border-radius: 10px;
}
.acciones .mas { color: var(--ok); }
.acciones .menos { color: var(--bad); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px;
}
.badge.bad { background: #fee2e2; color: var(--bad); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.info { background: #dbeafe; color: var(--azul); }

/* ---------- tablas ---------- */
.tabla { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--borde); border-radius: 14px; overflow: hidden; font-size: 14px; }
.tabla th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 10px 12px; background: var(--card2); border-bottom: 1px solid var(--borde); }
.tabla td { padding: 10px 12px; border-bottom: 1px solid var(--borde); }
.tabla tr:last-child td { border-bottom: none; }
.tabla td.num, .tabla th.num { text-align: right; white-space: nowrap; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-bg[hidden] { display: none; }
@media (min-width: 620px) { .modal-bg { align-items: center; } }
.modal {
  background: var(--bg); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; animation: up .18s ease-out;
}
@media (min-width: 620px) { .modal { border-radius: 18px; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.modal-acciones { display: flex; gap: 8px; margin-top: 16px; }
.modal-acciones button { flex: 1; }

/* ---------- navegación inferior ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--borde);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; text-align: center; padding: 9px 4px 10px; font-size: 11px; font-weight: 700;
  color: var(--muted);
}
.nav a .ic { display: block; font-size: 20px; line-height: 1.15; }
.nav a.on { color: var(--verde); }
.nav a .pill {
  display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 3px;
  background: var(--rojo); color: #fff; border-radius: 8px; font-size: 10px;
}

/* ---------- varios ---------- */
.vacio { text-align: center; color: var(--muted); padding: 34px 12px; font-size: 14px; }
.error { background: #fee2e2; color: var(--bad); padding: 10px 12px; border-radius: 11px;
  font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.aviso { background: #fef3c7; color: #92400e; padding: 10px 12px; border-radius: 11px;
  font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.toast {
  position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%);
  background: #111; color: #fff; padding: 11px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 700; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.3);
  animation: up .16s ease-out;
}
.toast[hidden] { display: none; }
.fab {
  position: fixed; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; background: var(--verde); color: #fff;
  border: none; font-size: 28px; font-weight: 400; z-index: 15;
  box-shadow: 0 6px 20px rgba(26,107,58,.4);
}

/* ---------- portada: tarjetas de grupo ---------- */
.grupos { display: flex; flex-direction: column; gap: 12px; }
.grupo-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--borde); border-radius: 16px;
  padding: 18px 16px; transition: .12s;
}
.grupo-card:active { transform: scale(.985); }
.grupo-card .ico {
  flex: 0 0 auto; width: 52px; height: 52px; border-radius: 14px; background: var(--card2);
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.grupo-card .txt { flex: 1 1 auto; min-width: 0; }
.grupo-card .txt b { display: block; font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
.grupo-card .txt span { font-size: 13px; color: var(--muted); }
.grupo-card .flecha { font-size: 24px; color: var(--muted); flex: 0 0 auto; }
.pendientes { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- menú de acciones del grupo ---------- */
.acciones-grupo { display: flex; flex-direction: column; gap: 12px; }
.accion {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--card); border: 1px solid var(--borde); border-radius: 16px;
  padding: 20px 16px; width: 100%; font-size: 17px; font-weight: 800;
}
.accion .ico { font-size: 26px; flex: 0 0 auto; }
.accion .txt { flex: 1 1 auto; }
.accion .txt small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 3px; }

/* ---------- filas de recuento / pedido ---------- */
.fila {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--borde); border-radius: 14px;
  padding: 10px 12px;
}
.fila .info { flex: 1 1 auto; min-width: 0; }
.fila .nom { font-size: 15px; font-weight: 700; line-height: 1.25; }
.fila .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.fila .meta b { color: var(--txt); font-weight: 800; }
.fila .caja { flex: 0 0 86px; }
.fila input[type=number] {
  text-align: center; font-size: 19px; font-weight: 800; padding: 12px 4px;
  -moz-appearance: textfield;
}
.fila input[type=number]::-webkit-outer-spin-button,
.fila input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.fila input.guardado { border-color: var(--ok); background: #f0fdf4; }
.fila input.fallo { border-color: var(--bad); background: #fef2f2; }
.fila.hecha { border-color: #bbf7d0; }

/* ---------- barra fija de acción ---------- */
.barra {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.97); backdrop-filter: blur(10px);
  border-top: 1px solid var(--borde);
}
.barra .resumen { flex: 1 1 auto; font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1.3; }
.barra .resumen b { color: var(--txt); font-size: 15px; }
.barra button { flex: 0 0 auto; padding: 13px 20px; font-size: 16px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: var(--card); border: 1px solid var(--borde); border-radius: 18px;
  padding: 26px 22px; width: 100%; max-width: 380px;
}
.login-card h1 { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
