:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --panel-2: #faf8f3;
  --text: #1f2a24;
  --textsub: #6b746e;
  --borde: #e4dfd3;
  --accent: #2f7d4f;
  --accent-texto: #ffffff;
  --accent-suave: #e3f0e7;
  --peligro: #c0392b;
  --tachado: #9aa19c;
  --sombra: 0 1px 2px rgba(40, 35, 20, 0.06), 0 4px 14px rgba(40, 35, 20, 0.06);
  --radio: 14px;
  --seguro-abajo: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111814;
    --panel: #1a231e;
    --panel-2: #1f2a24;
    --text: #e8ece9;
    --textsub: #98a39c;
    --borde: #2c3831;
    --accent: #4cb07a;
    --accent-texto: #0d1a12;
    --accent-suave: #1f3a2a;
    --peligro: #ef6b5b;
    --tachado: #69736d;
    --sombra: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Botones ---------- */
.btn {
  border: 1px solid var(--borde);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primario { background: var(--accent); color: var(--accent-texto); border-color: var(--accent); }
.btn-peligro { color: var(--peligro); }
.btn-linea { width: 100%; background: transparent; border-style: dashed; color: var(--textsub); margin-top: 6px; }
.btn-icono {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; fill: currentColor; flex: none; font-size: 18px;
}
.btn-icono:active { background: var(--accent-suave); }

input[type="text"], input[type="password"], select {
  width: 100%;
  border: 1px solid var(--borde);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-suave); }

/* ---------- Acceso ---------- */
.pantalla-acceso { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px; }
.acceso-caja { max-width: 360px; width: 100%; margin: 0 auto; text-align: center; }
.acceso-logo { border-radius: 18px; box-shadow: var(--sombra); }
.acceso-caja h1 { margin: 14px 0 4px; font-size: 26px; }
.acceso-paso { display: grid; gap: 12px; margin-top: 18px; }
.sub { color: var(--textsub); margin: 0; }
.error { color: var(--peligro); min-height: 1.4em; margin: 12px 0 0; }
.chips-usuarios { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip-usuario {
  border: 2px solid var(--c); color: var(--c); background: transparent; border-radius: 999px;
  padding: 8px 16px; font-weight: 700; cursor: pointer;
}

/* ---------- App ---------- */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.barra {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 8px 8px 12px; background: var(--bg);
}
.tabs { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--borde); background: var(--panel); border-radius: 999px;
  padding: 7px 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tab .n { color: var(--textsub); font-weight: 500; margin-left: 4px; }
.tab.activa { background: var(--accent); border-color: var(--accent); color: var(--accent-texto); }
.tab.activa .n { color: inherit; opacity: 0.8; }

.aviso-conexion {
  margin: 0 12px 6px; padding: 6px 12px; border-radius: 10px; font-size: 13px;
  background: #fff3cd; color: #7a5b00; text-align: center;
}
@media (prefers-color-scheme: dark) { .aviso-conexion { background: #3a3110; color: #f1d27a; } }

.contenido { flex: 1; padding: 4px 12px 140px; }

.grupo { margin-bottom: 14px; }
.grupo-titulo {
  display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--textsub); margin: 10px 4px 6px;
}
.grupo-titulo .acciones { margin-left: auto; text-transform: none; letter-spacing: 0; }
.tarjeta { background: var(--panel); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }

.item { display: flex; align-items: center; gap: 4px; min-height: 54px; border-top: 1px solid var(--borde); }
.item:first-child { border-top: 0; }
.item.destacado { animation: destello 1.2s ease; }
@keyframes destello { 0%, 40% { background: var(--accent-suave); } 100% { background: transparent; } }
.check {
  flex: none; width: 52px; height: 54px; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center;
}
.check span {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--borde);
  display: grid; place-items: center; transition: background 0.15s, border-color 0.15s;
}
.check:active span { border-color: var(--accent); }
.item.comprado .check span { background: var(--accent); border-color: var(--accent); }
.item.comprado .check span::after {
  content: ""; width: 6px; height: 11px; border: solid var(--accent-texto); border-width: 0 2.5px 2.5px 0;
  transform: translateY(-1px) rotate(45deg);
}
.item-cuerpo { flex: 1; min-width: 0; padding: 8px 4px 8px 0; cursor: pointer; }
.item-nombre { font-weight: 600; overflow-wrap: anywhere; }
.item-cant {
  display: inline-block; font-size: 13px; font-weight: 700; color: var(--accent);
  background: var(--accent-suave); border-radius: 6px; padding: 1px 7px; margin-left: 6px; vertical-align: 1px;
}
.item-nota { font-size: 13px; color: var(--textsub); overflow-wrap: anywhere; }
.item.comprado .item-nombre { color: var(--tachado); text-decoration: line-through; font-weight: 500; }
.item.comprado .item-cant { background: transparent; color: var(--tachado); }
.quien {
  flex: none; width: 26px; height: 26px; border-radius: 50%; margin-right: 12px;
  display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; background: var(--c);
}

.link { border: 0; background: transparent; color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px 6px; font-size: 13px; }
.link.peligro { color: var(--peligro); }

.vacio { text-align: center; color: var(--textsub); padding: 48px 20px 12px; }
.vacio .grande { font-size: 44px; }
.vacio p { margin: 8px 0 0; }

/* ---------- Agregar ---------- */
.agregar-zona {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 8px 12px calc(10px + var(--seguro-abajo));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.agregar-zona > * { max-width: 616px; margin-left: auto; margin-right: auto; }
.agregar { display: flex; gap: 8px; }
.agregar input { border-radius: 999px; padding: 13px 18px; background: var(--panel); box-shadow: var(--sombra); }
.btn-agregar {
  flex: none; width: 50px; height: 50px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-texto); display: grid; place-items: center; box-shadow: var(--sombra);
}
.sugerencias { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.sug {
  border: 1px solid var(--borde); background: var(--panel); border-radius: 999px; padding: 7px 12px;
  cursor: pointer; font-size: 14px; box-shadow: var(--sombra);
}
.sug b { font-weight: 700; }
.sug small { color: var(--textsub); margin-left: 4px; }
.sug-titulo { width: 100%; font-size: 12px; color: var(--textsub); margin: 0 4px; }

/* ---------- Hojas (dialog) ---------- */
dialog.hoja {
  border: 0; padding: 18px 16px calc(18px + var(--seguro-abajo)); width: 100%; max-width: 560px;
  background: var(--panel); color: var(--text); border-radius: 18px 18px 0 0;
  margin: auto auto 0; max-height: 92dvh; overflow-y: auto;
}
@media (min-width: 600px) { dialog.hoja { border-radius: 18px; margin: auto; } }
dialog.hoja::backdrop { background: rgba(10, 15, 12, 0.45); }
dialog.hoja-chica { max-width: 420px; }
.hoja h2 { margin: 0 0 14px; font-size: 20px; }
.hoja h3 { margin: 20px 0 8px; font-size: 15px; }
.sub-h { font-weight: 400; color: var(--textsub); font-size: 13px; }
.hoja-cabecera { display: flex; align-items: center; justify-content: space-between; }
.hoja-cabecera h2 { margin: 0; }
.hoja label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--textsub); margin-bottom: 12px; }
.hoja label input, .hoja label select { color: var(--text); font-weight: 400; font-size: 16px; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hoja-botones { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.espacio { flex: 1; }
.info-item { font-size: 12px; color: var(--textsub); margin: 0 0 6px; }
.fila-emoji { display: flex; gap: 8px; margin-bottom: 12px; }
.in-emoji { width: 58px !important; flex: none; text-align: center; font-size: 20px !important; }
.cf-texto { font-size: 17px; margin: 4px 0 14px; }

.lista-config { background: var(--panel-2); border: 1px solid var(--borde); border-radius: 12px; overflow: hidden; }
.cfg-fila { display: flex; align-items: center; gap: 2px; padding: 4px 4px 4px 12px; border-top: 1px solid var(--borde); }
.cfg-fila:first-child { border-top: 0; }
.cfg-fila .nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfg-fila .btn-icono { width: 36px; height: 36px; font-size: 15px; color: var(--textsub); }
.cfg-fila .btn-icono:disabled { opacity: 0.3; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 62px); transform: translateX(-50%); z-index: 20;
  background: #1f2a24; color: #fff; border-radius: 12px; padding: 10px 14px; display: flex; gap: 14px; align-items: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); max-width: calc(100% - 32px); font-size: 15px;
}
@media (prefers-color-scheme: dark) { .toast { background: #e8ece9; color: #111814; } }
.toast button { border: 0; background: transparent; color: #7fd6a3; font-weight: 800; cursor: pointer; padding: 2px 4px; }
@media (prefers-color-scheme: dark) { .toast button { color: #2f7d4f; } }

.onix-footer { text-align: center; font-size: 12px; color: var(--textsub); padding: 22px 0 4px; }
.onix-footer a { color: var(--textsub); font-weight: 600; text-decoration: none; }
.onix-footer a:hover { color: var(--accent); text-decoration: underline; }
